Comparing version 3.1.0-pre.2 to 3.1.0-pre.3
@@ -8,2 +8,4 @@ /* jshint asi:true */ | ||
var observeReader = require('can-observation/reader/reader'); | ||
var canReflect = require('can-reflect'); | ||
var canSymbol = require('can-symbol'); | ||
@@ -263,7 +265,7 @@ QUnit.module('can-map'); | ||
equal(map._bindings, 1, 'The number of bindings is correct'); | ||
equal(map.__bindEvents._lifecycleBindings, 1, 'The number of bindings is correct'); | ||
map.off('undefined_property'); | ||
equal(map._bindings, 1, 'The number of bindings is still correct'); | ||
equal(map.__bindEvents._lifecycleBindings, 1, 'The number of bindings is still correct'); | ||
}); | ||
@@ -370,1 +372,67 @@ | ||
}); | ||
test("works with can-reflect", 9, function(){ | ||
var c = new Map({ "foo": "bar" }); | ||
QUnit.equal( canReflect.getKeyValue(c, "foo"), "bar", "unbound value"); | ||
var handler = function(newValue){ | ||
QUnit.equal(newValue, "baz", "observed new value"); | ||
// Turn off the "foo" handler but "thud" should still be bound. | ||
canReflect.offKeyValue(c, "foo", handler); | ||
}; | ||
QUnit.ok(!canReflect.isValueLike(c), "isValueLike is false"); | ||
QUnit.ok(canReflect.isMapLike(c), "isMapLike is true"); | ||
QUnit.ok(!canReflect.isListLike(c), "isListLike is false"); | ||
QUnit.ok( !canReflect.keyHasDependencies(c, "foo"), "keyHasDependencies -- false"); | ||
canReflect.onKeyValue(c, "foo", handler); | ||
// Do a second binding to check that you can unbind correctly. | ||
canReflect.onKeyValue(c, "thud", handler); | ||
QUnit.ok( canReflect.keyHasDependencies(c, "foo"), "keyHasDependencies -- true"); | ||
c.attr("foo", "baz"); | ||
c.attr("thud", "baz"); | ||
QUnit.equal( canReflect.getKeyValue(c, "foo"), "baz", "bound value"); | ||
c.attr("foo", "quux"); | ||
}); | ||
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({ "a": "a" }); | ||
ok(!canReflect.getKeyDependencies(a, "a"), "No dependencies before binding"); | ||
a.on("a", function() {}); | ||
ok(canReflect.getKeyDependencies(a, "a"), "dependencies exist"); | ||
equal(canReflect.getKeyDependencies(a, "a"), a.__bindEvents.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 | ||
}); |
@@ -26,2 +26,5 @@ /* jshint -W079 */ | ||
var canCompute = require('can-compute'); | ||
// TODO update this to use 'can-util/js/single-reference/single-reference' once the canReflect | ||
// updates from can-compute/single-reference are merged into it. | ||
var singleReference = require('can-compute/single-reference'); | ||
@@ -35,3 +38,4 @@ var namespace = require("can-namespace"); | ||
var types = require("can-types"); | ||
var isArray = require("can-util/js/is-array/is-array"); | ||
var canReflect = require("can-reflect"); | ||
var canSymbol = require("can-symbol"); | ||
@@ -43,2 +47,5 @@ // properties that can't be observed on ... no matter what | ||
var hasOwnProperty = ({}).hasOwnProperty; | ||
var setValueSymbol = canSymbol.for("can.setValue"); | ||
// Extend [can.Construct](../construct/construct.html) to make inheriting a `can.Map` easier. | ||
@@ -134,4 +141,4 @@ var Map = Construct.extend( | ||
// are here mostly for can.Model. | ||
addEventListener: eventLifecycle.addAndSetup, | ||
removeEventListener: eventLifecycle.removeAndTeardown, | ||
addEventListener: eventLifecycle.addAndSetup, | ||
removeEventListener: eventLifecycle.removeAndTeardown, | ||
@@ -141,8 +148,4 @@ // ### keys | ||
keys: function (map) { | ||
var keys = []; | ||
Observation.add(map, '__keys'); | ||
for (var keyName in map._data) { | ||
keys.push(keyName); | ||
} | ||
return keys; | ||
return canReflect.getOwnEnumerableKeys(map._data); | ||
} | ||
@@ -159,3 +162,3 @@ }, | ||
if(obj instanceof Map){ | ||
if(canReflect.isObservableLike(obj) && typeof obj.serialize === "function"){ | ||
obj = obj.serialize(); | ||
@@ -165,3 +168,3 @@ } | ||
// Where we keep the values of the compute. | ||
this._data = {}; | ||
this._data = Object.create(null); | ||
@@ -201,3 +204,3 @@ // The namespace this `object` uses to listen to events. | ||
_setupComputedProperties: function () { | ||
this._computedAttrs = {}; | ||
this._computedAttrs = Object.create(null); | ||
@@ -264,3 +267,3 @@ var computes = this.constructor._computedPropertyNames; | ||
return current && current._get ? current._get(second) : undefined; | ||
return current && canReflect.getKeyValue(current, second); | ||
} else { | ||
@@ -292,3 +295,3 @@ return this.__get( attr ); | ||
} else { | ||
return this._data.hasOwnProperty(attr) ? this._data[attr] : undefined; | ||
return hasOwnProperty.call(this._data, attr) ? this._data[attr] : undefined; | ||
} | ||
@@ -321,4 +324,4 @@ } else { | ||
if( types.isMapLike(current) ) { | ||
current._set(second, value); | ||
if( canReflect.isMapLike(current) ) { | ||
canReflect.setKeyValue(current, second, value); | ||
} else { | ||
@@ -349,3 +352,7 @@ throw new Error("can-map: Object does not exist"); | ||
if (typeof value === "object" && !types.isMapLike( value ) && mapHelpers.canMakeObserve(value) && !isArray(value) ) { | ||
if (typeof value === "object" && | ||
!canReflect.isObservableLike( value ) && | ||
mapHelpers.canMakeObserve(value) && | ||
!canReflect.isListLike(value) | ||
) { | ||
@@ -373,4 +380,4 @@ var cached = mapHelpers.getMapFromObject(value); | ||
// Dispatch an "add" event if adding a new property. | ||
var changeType = computedAttr || current !== undefined || this.___get() | ||
.hasOwnProperty(prop) ? "set" : "add"; | ||
var changeType = computedAttr || current !== undefined || | ||
hasOwnProperty.call(this.___get(), prop) ? "set" : "add"; | ||
@@ -429,3 +436,3 @@ // Set the value on `_data` and set up bubbling. | ||
if (parts.length && current) { | ||
return current.removeAttr(parts); | ||
return canReflect.deleteKeyValue(current, parts.join(".")); | ||
} else { | ||
@@ -508,4 +515,14 @@ | ||
if ( types.isMapLike(curVal) && mapHelpers.canMakeObserve(newVal) ) { | ||
curVal.attr(newVal, remove); | ||
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); | ||
} | ||
}); | ||
} | ||
// Otherwise just set. | ||
@@ -587,3 +604,3 @@ } else if (curVal !== newVal) { | ||
computedBinding.count = 1; | ||
computedBinding.compute.addEventListener("change", computedBinding.handler); | ||
canReflect.onValue(computedBinding.compute, computedBinding.handler); | ||
} else { | ||
@@ -610,3 +627,3 @@ computedBinding.count++; | ||
computedBinding.count = 0; | ||
computedBinding.compute.removeEventListener("change", computedBinding.handler); | ||
canReflect.offValue(computedBinding.compute, computedBinding.handler); | ||
} else { | ||
@@ -665,3 +682,3 @@ computedBinding.count--; | ||
for (var prop in data) { | ||
if (data.hasOwnProperty(prop)) { | ||
if (hasOwnProperty.call(data, prop)) { | ||
callback(data[prop], prop); | ||
@@ -685,2 +702,30 @@ } | ||
canReflect.set(Map.prototype, canSymbol.for("can.onKeyValue"), function(key, handler){ | ||
var translationHandler = function(ev, newValue){ | ||
handler(newValue); | ||
}; | ||
singleReference.set(handler, this, translationHandler, key); | ||
this.addEventListener(key, translationHandler); | ||
}); | ||
canReflect.set(Map.prototype, canSymbol.for("can.offKeyValue"), function(key, handler){ | ||
this.removeEventListener(key, singleReference.getAndDelete(handler, this, key) ); | ||
}); | ||
// Setup other symbols | ||
Map.prototype[canSymbol.for("can.isMapLike")] = true; | ||
Map.prototype[canSymbol.for("can.isListLike")] = false; | ||
Map.prototype[canSymbol.for("can.isValueLike")] = false; | ||
Map.prototype[canSymbol.for("can.getKeyValue")] = Map.prototype._get; | ||
Map.prototype[canSymbol.for("can.setKeyValue")] = Map.prototype._set; | ||
Map.prototype[setValueSymbol] = Map.prototype._setAttrs; | ||
Map.prototype[canSymbol.for("can.deleteKeyValue")] = Map.prototype._remove; | ||
Map.prototype[canSymbol.for("can.keyHasDependencies")] = function(key) { | ||
return !!this.__bindEvents && this.__bindEvents[key].length > 0; | ||
}; | ||
Map.prototype[canSymbol.for("can.getKeyDependencies")] = function(key) { | ||
return this.__bindEvents && this.__bindEvents[key]; | ||
}; | ||
var oldIsMapLike = types.isMapLike; | ||
@@ -687,0 +732,0 @@ types.isMapLike = function(obj){ |
{ | ||
"name": "can-map", | ||
"version": "3.1.0-pre.2", | ||
"version": "3.1.0-pre.3", | ||
"description": "Observable Objects", | ||
@@ -39,9 +39,11 @@ "homepage": "http://canjs.com", | ||
"can-cid": "^1.0.0", | ||
"can-compute": "^3.1.0-pre.1", | ||
"can-compute": "^3.1.0-pre.4", | ||
"can-construct": "^3.0.0", | ||
"can-event": "^3.0.1", | ||
"can-namespace": "^1.0.0", | ||
"can-observation": "^3.2.0-pre.3", | ||
"can-observation": "^3.2.0-pre.7", | ||
"can-reflect": "0.0.2", | ||
"can-symbol": "0.0.3", | ||
"can-types": "^1.0.1", | ||
"can-util": "^3.2.2" | ||
"can-util": "^3.7.0" | ||
}, | ||
@@ -48,0 +50,0 @@ "devDependencies": { |
Major refactor
Supply chain riskPackage has recently undergone a major refactor. It may be unstable or indicate significant internal changes. Use caution when updating to versions that include significant changes.
Found 1 instance in 1 package
293359
98
6101
10
1
+ Addedcan-reflect@0.0.2
+ Addedcan-symbol@0.0.3
+ Addedcan-reflect@0.0.2(transitive)
+ Addedcan-symbol@0.0.3(transitive)
+ Addedcssify@0.6.0(transitive)
+ Addedthrough@2.3.8(transitive)
Updatedcan-compute@^3.1.0-pre.4
Updatedcan-observation@^3.2.0-pre.7
Updatedcan-util@^3.7.0