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.0.5 to 3.1.0-pre.0

109

can-list_test.js

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

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

@@ -104,3 +105,4 @@ QUnit.module('can-list');

});
equal(o.attr('foo'), 'bar');
equal(o.attr('foo'), 'bar', "read foo property");
o.attr('foo', 'car');

@@ -202,3 +204,3 @@ l.pop();

var Animal = Map.extend();
var me = new Person({ name: "John" });

@@ -208,3 +210,3 @@ var animal = new Animal({ name: "Tak" });

var hero = { name: "Ghandi" };
var people = new People([]);

@@ -215,5 +217,5 @@ var specialPeople = new People([

]);
people = people.concat([me, animal, specialPeople], specialPeople, [1, 2], 3);
ok(people.attr('length') === 8, "List length is right");

@@ -412,17 +414,2 @@ ok(people[0] === me, "Map in list === vars created before concat");

test("works with can-map-define", function() {
var MyList = List.extend({}, {
define: {
foo: {
get: function(){
return "bar";
}
}
}
});
var list = new MyList();
equal(list.attr("foo"), "bar");
});
test('forEach callback', function () {

@@ -476,1 +463,81 @@ var list = new 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 = {
compute: new Observation(function() {
return a.attr("foo");
}, null)
};
b._computedAttrs.length.compute.start();
ok(canReflect.getKeyDependencies(b, "length"), "dependencies exist");
ok(canReflect.getKeyDependencies(b, "length").valueDependencies.has(b._computedAttrs.length.compute), "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
});

114

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 CIDMap = require("can-util/js/cid-map/cid-map");
// 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 {

@@ -224,3 +226,3 @@ return this[attr];

serialize: function () {
return mapHelpers.serialize(this, 'serialize', []);
return canReflect.serialize(this, CIDMap);
},

@@ -238,3 +240,3 @@ /**

* arguments, respectively, to the callback. If the callback returns false,
* the loop will stop. The callback is not invoked for List elements that were
* the loop will stop. The callback is not invoked for List elements that were
* never initialized.

@@ -381,37 +383,2 @@ *

return removed;
},
_getAttrs: function(){
return mapHelpers.serialize(this, 'attr', []);
},
_setAttrs: function (items, remove) {
// Create a copy.
items = makeArray(items);
canBatch.start();
this._updateAttrs(items, remove);
canBatch.stop();
},
_updateAttrs: function (items, remove) {
var len = Math.min(items.length, this.length);
for (var prop = 0; prop < len; prop++) {
var curVal = this[prop],
newVal = items[prop];
if ( types.isMapLike(curVal) && mapHelpers.canMakeObserve(newVal)) {
curVal.attr(newVal, remove);
//changed from a coercion to an explicit
} else if (curVal !== newVal) {
this._set(prop+"", newVal);
} else {
}
}
if (items.length > this.length) {
// Add in the remaining props.
this.push.apply(this, items.slice(this.length));
} else if (items.length < this.length && remove) {
this.splice(items.length);
}
}

@@ -792,9 +759,9 @@ }),

MapType = this.constructor.Map;
// Go through each of the passed `arguments` and
// Go through each of the passed `arguments` and
// see if it is list-like, an array, or something else
each(arguments, function(arg) {
if(types.isListLike(arg) || Array.isArray(arg)) {
if((canReflect.isObservableLike(arg) && canReflect.isListLike(arg)) || Array.isArray(arg)) {
// If it is list-like we want convert to a JS array then
// pass each item of the array to serializeNonTypes
var arr = types.isListLike(arg) ? makeArray(arg) : arg;
var arr = (canReflect.isObservableLike(arg) && canReflect.isListLike(arg)) ? makeArray(arg) : arg;
each(arr, function(innerArg) {

@@ -805,3 +772,3 @@ serializeNonTypes(MapType, innerArg, args);

else {
// If it is a Map, Object, or some primitive
// If it is a Map, Object, or some primitive
// just pass arg to serializeNonTypes

@@ -825,3 +792,3 @@ serializeNonTypes(MapType, arg, args);

* The three parameters that _callback_ gets passed are _element_, the element at _index_, _index_ the
* current element of the list, and _list_ the List the elements are coming from. _callback_ is
* current element of the list, and _list_ the List the elements are coming from. _callback_ is
* not invoked for List elements that were never initialized.

@@ -957,8 +924,2 @@ * @param {Object} [thisArg] the object to use as `this` inside the callback

// specify the type
var oldIsListLike = types.isListLike;
types.isListLike = function(obj){
return obj instanceof List || oldIsListLike.apply(this, arguments);
};
// change some map stuff to include list stuff

@@ -995,4 +956,55 @@ var oldType = Map.prototype.__type;

// Setup other symbols
canReflect.assignSymbols(List.prototype,{
// -type-
"can.isMoreListLikeThanMapLike": true,
"can.isListLike": true,
// -get/set-
"can.getKeyValue": List.prototype._get,
"can.setKeyValue": List.prototype._set,
"can.deleteKeyValue": List.prototype._remove,
// -shape
"can.getOwnEnumerableKeys": function(){
return Object.keys(this._data || {}).concat(this.map(function(val, index) {
return index;
}));
},
// -shape get/set-
"can.assignDeep": function(source){
canBatch.start();
// TODO: we should probably just throw an error instead of cleaning
canReflect.assignDeepList(this, source);
canBatch.stop();
},
"can.updateDeep": function(source){
canBatch.start();
// TODO: we should probably just throw an error instead of cleaning
canReflect.updateDeepList(this, source);
canBatch.stop();
},
"can.unwrap": mapHelpers.reflectUnwrap,
"can.serialize": mapHelpers.reflectSerialize,
// observable
"can.onKeysAdded": function(handler) {
this[canSymbol.for("can.onKeyValue")]("add", handler);
},
"can.onKeysRemoved": function(handler) {
this[canSymbol.for("can.onKeyValue")]("remove", handler);
}
});
// @@can.keyHasDependencies and @@can.getKeyDependencies same as can-map
List.prototype.each = List.prototype.forEach;
Map.List = List;
module.exports = namespace.List = List;
{
"name": "can-list",
"version": "3.0.5",
"version": "3.1.0-pre.0",
"description": "Observable lists",

@@ -18,2 +18,3 @@ "homepage": "http://canjs.com",

"jshint": "jshint ./*.js --config",
"release:pre": "npm version prerelease && npm publish --tag pre",
"release:patch": "npm version patch && npm publish",

@@ -24,4 +25,3 @@ "release:minor": "npm version minor && npm publish",

"document": "bit-docs",
"develop": "done-serve --static --develop --port 8080",
"release:pre": "npm version prerelease && npm publish"
"develop": "done-serve --static --develop --port 8080"
},

@@ -42,13 +42,15 @@ "main": "can-list",

"can-cid": "^1.0.0",
"can-construct": "^3.0.0",
"can-event": "^3.3.0",
"can-map": "^3.0.7",
"can-compute": "^3.1.0-pre.9",
"can-construct": "^3.2.0-pre.0",
"can-event": "^3.5.0-pre.2",
"can-map": "^3.3.0-pre.0",
"can-namespace": "1.0.0",
"can-observation": "^3.0.1",
"can-types": "^1.0.1",
"can-util": "^3.2.2"
"can-observation": "^3.2.0-pre.9",
"can-reflect": "^1.1.0-pre.0",
"can-symbol": "^1.0.0-pre.0",
"can-types": "^1.1.0-pre.2",
"can-util": "^3.9.0-pre.1"
},
"devDependencies": {
"bit-docs": "0.0.7",
"can-map-define": "^3.0.2",
"done-serve": "^0.2.0",

@@ -55,0 +57,0 @@ "donejs-cli": "^0.9.5",

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