Created
January 17, 2012 20:30
-
-
Save jmarnold/1628702 to your computer and use it in GitHub Desktop.
Found the newer one
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Backbone.Model.prototype.dependentProperty = function (name, origin, evaluator) { | |
var update = function () { | |
var value = evaluator.call(this); | |
var hash = {}; | |
hash[name] = value; | |
this.set(hash); | |
}; | |
this.bind('change:' + origin, function () { | |
update.call(this); | |
}); | |
update.call(this); | |
}; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
describe('BackboneDependentPropertyTester', function () { | |
it('should_update_when_target_updates', function () { | |
var model = new (Backbone.Model.extend({ | |
initialize: function () { | |
this.dependentProperty('y', 'x', function () { | |
return this.get('x') * 100; | |
}); | |
} | |
})); | |
model.set({ x: 5 }); | |
expect(model.get('y')).toEqual(500); | |
}); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment