can-define
Advanced tools
Comparing version 0.7.25 to 0.7.27
@@ -36,9 +36,19 @@ "use strict"; | ||
module.exports = define = ns.define = function(objPrototype, defines) { | ||
var simpleEach = function(map, cb){ | ||
for(var prop in map) { | ||
if(map.hasOwnProperty(prop)) { | ||
cb(map[prop], prop); | ||
} | ||
} | ||
}; | ||
module.exports = define = ns.define = function(objPrototype, defines, baseDefine) { | ||
// default property definitions on _data | ||
var dataInitializers = {}, | ||
var dataInitializers = Object.create(baseDefine ? baseDefine.dataInitializers : null), | ||
// computed property definitions on _computed | ||
computedInitializers = {}; | ||
computedInitializers = Object.create(baseDefine ? baseDefine.computedInitializers : null); | ||
var result = getDefinitionsAndMethods(defines); | ||
result.dataInitializers = dataInitializers; | ||
result.computedInitializers = computedInitializers; | ||
@@ -93,9 +103,9 @@ // Goes through each property definition and creates | ||
// Places Symbol.iterator or @@iterator on the prototype | ||
// so that this can be iterated with for/of and can-util/js/each/each | ||
if(!objPrototype[types.iterator]) { | ||
defineConfigurableAndNotEnumerable(objPrototype, types.iterator, function(){ | ||
return new define.Iterator(this); | ||
}); | ||
} | ||
// Places Symbol.iterator or @@iterator on the prototype | ||
// so that this can be iterated with for/of and can-util/js/each/each | ||
if(!objPrototype[types.iterator]) { | ||
defineConfigurableAndNotEnumerable(objPrototype, types.iterator, function(){ | ||
return new define.Iterator(this); | ||
}); | ||
} | ||
@@ -513,3 +523,3 @@ return result; | ||
canEach(defines, function(value, prop) { | ||
simpleEach(defines, function(value, prop) { | ||
if(prop === "constructor") { | ||
@@ -516,0 +526,0 @@ methods[prop] = value; |
@@ -48,2 +48,3 @@ "use strict"; | ||
QUnit.test("setting not defined property", function(){ | ||
@@ -297,1 +298,80 @@ var MyMap = DefineMap.extend({ | ||
}); | ||
QUnit.test("extending DefineMap constructor functions (#18)", function(){ | ||
var AType = DefineMap.extend("AType", { aProp: {}, aMethod: function(){} }); | ||
var BType = AType.extend("BType", { bProp: {}, bMethod: function(){} }); | ||
var CType = BType.extend("CType", { cProp: {}, cMethod: function(){} }); | ||
var map = new CType(); | ||
map.on("aProp", function(ev, newVal, oldVal){ | ||
QUnit.equal(newVal, "PROP"); | ||
QUnit.equal(oldVal, undefined); | ||
}); | ||
map.on("bProp", function(ev, newVal, oldVal){ | ||
QUnit.equal(newVal, "FOO"); | ||
QUnit.equal(oldVal, undefined); | ||
}); | ||
map.on("cProp", function(ev, newVal, oldVal){ | ||
QUnit.equal(newVal, "BAR"); | ||
QUnit.equal(oldVal, undefined); | ||
}); | ||
map.aProp = "PROP"; | ||
map.bProp = 'FOO'; | ||
map.cProp = 'BAR'; | ||
QUnit.ok(map.aMethod); | ||
QUnit.ok(map.bMethod); | ||
QUnit.ok(map.cMethod); | ||
}); | ||
QUnit.test("extending DefineMap constructor functions more than once (#18)", function(){ | ||
var AType = DefineMap.extend("AType", { aProp: {}, aMethod: function(){} }); | ||
var BType = AType.extend("BType", { bProp: {}, bMethod: function(){} }); | ||
var CType = AType.extend("CType", { cProp: {}, cMethod: function(){} }); | ||
var map1 = new BType(); | ||
var map2 = new CType(); | ||
map1.on("aProp", function(ev, newVal, oldVal){ | ||
QUnit.equal(newVal, "PROP", "aProp newVal on map1"); | ||
QUnit.equal(oldVal, undefined); | ||
}); | ||
map1.on("bProp", function(ev, newVal, oldVal){ | ||
QUnit.equal(newVal, "FOO", "bProp newVal on map1"); | ||
QUnit.equal(oldVal, undefined); | ||
}); | ||
map2.on("aProp", function(ev, newVal, oldVal){ | ||
QUnit.equal(newVal, "PROP", "aProp newVal on map2"); | ||
QUnit.equal(oldVal, undefined); | ||
}); | ||
map2.on("cProp", function(ev, newVal, oldVal){ | ||
QUnit.equal(newVal, "BAR", "cProp newVal on map2"); | ||
QUnit.equal(oldVal, undefined); | ||
}); | ||
map1.aProp = "PROP"; | ||
map1.bProp = 'FOO'; | ||
map2.aProp = "PROP"; | ||
map2.cProp = 'BAR'; | ||
QUnit.ok(map1.aMethod, "map1 aMethod"); | ||
QUnit.ok(map1.bMethod); | ||
QUnit.ok(map2.aMethod); | ||
QUnit.ok(map2.cMethod, "map2 cMethod"); | ||
}); | ||
QUnit.test("extending DefineMap constructor functions - value (#18)", function(){ | ||
var AType = DefineMap.extend("AType", { aProp: {value: 1} }); | ||
var BType = AType.extend("BType", { }); | ||
var CType = BType.extend("CType",{ }); | ||
var c = new CType(); | ||
QUnit.equal( c.aProp , 1 ,"got initial value" ); | ||
}); |
@@ -84,9 +84,7 @@ var Construct = require("can-construct"); | ||
var DefineMap = Construct.extend("DefineMap",{ | ||
setup: function(){ | ||
setup: function(base){ | ||
if(DefineMap) { | ||
var prototype = this.prototype; | ||
define(prototype, prototype); | ||
define(prototype, prototype, base.prototype._define); | ||
@@ -93,0 +91,0 @@ this.prototype.setup = function(props){ |
{ | ||
"name": "can-define", | ||
"version": "0.7.25", | ||
"version": "0.7.27", | ||
"description": "Like can.Map, but without the .attr method.", | ||
@@ -5,0 +5,0 @@ "main": "can-define.js", |
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
190310
4056