Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

can-list

Package Overview
Dependencies
Maintainers
8
Versions
57
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

can-list - npm Package Compare versions

Comparing version 3.1.0-pre.1 to 3.1.0-pre.2

node_modules/can-list/.editorconfig

83

can-list_test.js

@@ -5,2 +5,4 @@ var List = require('can-list');

var Map = require('can-map');
var canReflect = require('can-reflect');
var canSymbol = require('can-symbol');

@@ -428,1 +430,82 @@ QUnit.module('can-list');

});
test("works with can-reflect", 11, function(){
var a = new Map({ foo: 4 });
var b = new List([ "foo", "bar" ]);
QUnit.equal( canReflect.getKeyValue(b, "0"), "foo", "unbound value");
var handler = function(newValue){
QUnit.equal(newValue, "quux", "observed new value");
};
QUnit.ok(!canReflect.isValueLike(b), "isValueLike is false");
QUnit.ok(canReflect.isMapLike(b), "isMapLike is true");
QUnit.ok(canReflect.isListLike(b), "isListLike is false");
QUnit.ok( !canReflect.keyHasDependencies(b, "length"), "keyHasDependencies -- false");
b._computedAttrs["length"] = { // jshint ignore:line
compute: new Observation(function() {
return a.attr("foo");
}, null)
};
b._computedAttrs["length"].compute.start(); // jshint ignore:line
QUnit.ok( canReflect.keyHasDependencies(b, "length"), "keyHasDependencies -- true");
canReflect.onKeysAdded(b, handler);
canReflect.onKeysRemoved(b, handler);
QUnit.ok(b.__bindEvents.add, "add handler added");
QUnit.ok(b.__bindEvents.remove, "remove handler added");
b.push("quux");
QUnit.equal( canReflect.getKeyValue(b, "length"), "4", "bound value");
// sanity checks to ensure that handler doesn't get called again.
b.pop();
});
QUnit.test("can-reflect setKeyValue", function(){
var a = new Map({ "a": "b" });
canReflect.setKeyValue(a, "a", "c");
QUnit.equal(a.attr("a"), "c", "setKeyValue");
});
QUnit.test("can-reflect getKeyDependencies", function() {
var a = new Map({ foo: 4 });
var b = new List([ "foo", "bar" ]);
ok(!canReflect.getKeyDependencies(b, "length"), "No dependencies before binding");
b._computedAttrs["length"] = { // jshint ignore:line
compute: new Observation(function() {
return a.attr("foo");
}, null)
};
b._computedAttrs["length"].compute.start(); // jshint ignore:line
ok(canReflect.getKeyDependencies(b, "length"), "dependencies exist");
ok(canReflect.getKeyDependencies(b, "length").keyDependencies.has(a), "dependencies returned");
});
QUnit.test("registered symbols", function() {
var a = new Map({ "a": "a" });
ok(a[canSymbol.for("can.isMapLike")], "can.isMapLike");
equal(a[canSymbol.for("can.getKeyValue")]("a"), "a", "can.getKeyValue");
a[canSymbol.for("can.setKeyValue")]("a", "b");
equal(a.attr("a"), "b", "can.setKeyValue");
function handler(val) {
equal(val, "c", "can.onKeyValue");
}
a[canSymbol.for("can.onKeyValue")]("a", handler);
a.attr("a", "c");
a[canSymbol.for("can.offKeyValue")]("a", handler);
a.attr("a", "d"); // doesn't trigger handler
});

36

can-list.js

@@ -18,5 +18,7 @@ /* jshint -W079 */

var each = require('can-util/js/each/each');
var canReflect = require('can-reflect');
var canSymbol = require('can-symbol');
var setValueSymbol = canSymbol.for("can.setValue");
// Helpers for `observable` lists.

@@ -163,7 +165,7 @@ var splice = [].splice,

if(computedAttr && computedAttr.compute) {
return computedAttr.compute();
return canReflect.getValue(computedAttr.compute);
}
if (this[attr] && this[attr].isComputed && typeof this.constructor.prototype[attr] === "function" ) {
return this[attr]();
return canReflect.getValue(this[attr]);
} else {

@@ -399,5 +401,14 @@ return this[attr];

if ( types.isMapLike(curVal) && mapHelpers.canMakeObserve(newVal)) {
curVal.attr(newVal, remove);
//changed from a coercion to an explicit
if ( canReflect.isMapLike(curVal) && mapHelpers.canMakeObserve(newVal)) {
if (setValueSymbol in curVal) {
curVal[setValueSymbol](newVal, remove);
} else {
canReflect.eachKey(curVal, function(val, key) {
if (newVal[key]) {
canReflect.setKeyValue(curVal, key, val);
} else if (remove) {
canReflect.deleteKeyValue(curVal, key);
}
});
}
} else if (curVal !== newVal) {

@@ -989,4 +1000,17 @@ this._set(prop+"", newVal);

// Setup other symbols
List.prototype[canSymbol.for("can.isListLike")] = true;
List.prototype[canSymbol.for("can.getKeyValue")] = List.prototype._get;
List.prototype[canSymbol.for("can.setKeyValue")] = List.prototype._set;
List.prototype[canSymbol.for("can.deleteKeyValue")] = List.prototype._remove;
// @@can.keyHasDependencies and @@can.getKeyDependencies same as can-map
List.prototype[canSymbol.for("can.onKeysAdded")] = function(handler) {
this[canSymbol.for("can.onKeyValue")]("add", handler);
};
List.prototype[canSymbol.for("can.onKeysRemoved")] = function(handler) {
this[canSymbol.for("can.onKeyValue")]("remove", handler);
};
List.prototype.each = List.prototype.forEach;
Map.List = List;
module.exports = namespace.List = List;

10

package.json
{
"name": "can-list",
"version": "3.1.0-pre.1",
"version": "3.1.0-pre.2",
"description": "Observable lists",

@@ -41,6 +41,8 @@ "homepage": "http://canjs.com",

"can-construct": "^3.0.0",
"can-event": "^3.0.1",
"can-map": "^3.1.0-pre.2",
"can-event": "^3.3.0",
"can-map": "^3.1.0-pre.4",
"can-namespace": "1.0.0",
"can-observation": "^3.2.0-pre.5",
"can-observation": "^3.2.0-pre.8",
"can-reflect": "0.0.2",
"can-symbol": "0.0.3",
"can-types": "^1.0.1",

@@ -47,0 +49,0 @@ "can-util": "^3.1.1"

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc