Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

cell: call set for mixin passed to constructor

  • Loading branch information...
commit 2c4a72fc7a0333f36b63178b8066ced5f26c9c89 1 parent 246aa1e
@neonstalwart authored
Showing with 24 additions and 2 deletions.
  1. +9 −2 Cell.js
  2. +15 −0 CellTest.js
View
11 Cell.js
@@ -20,13 +20,20 @@ function (require, exports, module, undefined) {
hasOwn = Object.prototype.hasOwnProperty,
useNative;
- module.exports = Cell = compose(function () {
+ module.exports = Cell = compose(function (mixin) {
var cell = this._cell || (this._cell = {}),
- descriptors = cell.descriptors;
+ descriptors = cell.descriptors || {},
+ p, val;
if (useNative && descriptors) {
Object.defineProperties(this, descriptors);
}
+
+ for (p in mixin) {
+ val = mixin[p];
+ if (typeof val !== 'function') this.set(p, val);
+ else this[p] = val;
+ }
},
{
get: function (key) {
View
15 CellTest.js
@@ -191,6 +191,21 @@ function (require, exports, module, undefined) {
assert.equal(test.get('foo'), foo, 'getting without descriptor');
assert.equal(test.set('bar', bar), bar, 'setting without descriptor');
+ },
+
+ 'test constructor calls set for each property in mixin': function () {
+ var mixin = {
+ a: 'a',
+ b: 'b'
+ },
+ Ctor = Cell.extend({
+ set: this.spy()
+ }),
+ cell = new Ctor(mixin);
+
+ Object.keys(mixin).forEach(function (key) {
+ assert.ok(cell.set.calledWith(key, mixin[key]), 'constructor called set for ' + key);
+ });
}
})
});
Please sign in to comment.
Something went wrong with that request. Please try again.