Skip to content

Commit

Permalink
fixes two way live binding
Browse files Browse the repository at this point in the history
  • Loading branch information
justinbmeyer committed May 1, 2013
1 parent 326e104 commit e045696
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 7 deletions.
8 changes: 6 additions & 2 deletions observe/compute/compute.js
Original file line number Diff line number Diff line change
Expand Up @@ -348,16 +348,20 @@ steal('can/util', 'can/util/bind', function(can, bind) {
// setter is for a value maintained exclusively by this compute
var setVal = set.call(context,newVal, old);

// if this has dependencies return the current value
if(computed.hasDependencies){
return get.call(context);
}

if(setVal === undefined) {
// it's possible, like with the DOM, setting does not
// fire a change event, so we must read
value = get.call(context);
} else {
value = setVal;
}
// if computed has dependencies, changes to those dependencies will
// fire the change
if( old !== value && !computed.hasDependencies){
if( old !== value){
can.Observe.triggerBatch(computed, "change",[value, old] );
}
return value;
Expand Down
15 changes: 10 additions & 5 deletions observe/observe.js
Original file line number Diff line number Diff line change
Expand Up @@ -125,8 +125,8 @@ steal('can/util','can/util/bind','can/construct', function(can, bind) {
* @static
*/
// keep so it can be overwritten
bind : can.bindAndSetup,
unbind: can.unbindAndTeardown,
bind : bind.bindAndSetup,
unbind: bind.unbindAndTeardown,
id: "id",
canMakeObserve : canMakeObserve,
// starts collecting events
Expand Down Expand Up @@ -790,7 +790,7 @@ steal('can/util','can/util/bind','can/construct', function(can, bind) {
*
* @return {can.Observe} the observe for chaining.
*/
bind: can.bindAndSetup,
bind: bind.bindAndSetup,
/**
* @function unbind
* Unbinds an event listener. This works similar to jQuery's unbind. This means you can
Expand All @@ -814,7 +814,7 @@ steal('can/util','can/util/bind','can/construct', function(can, bind) {
*
* @return {can.Observe} the original observe for chaining.
*/
unbind: can.unbindAndTeardown,
unbind: bind.unbindAndTeardown,
/**
* @hide
* Get the serialized Object form of the observe. Serialized
Expand Down Expand Up @@ -915,7 +915,12 @@ steal('can/util','can/util/bind','can/construct', function(can, bind) {
* @return {can.compute} A can.compute instance
*/
compute: function(prop) {
return can.compute(this,prop)
var self = this,
computer = function(val) {
return self.attr(prop, val);
};

return can.compute ? can.compute(computer) : computer;
}
});
// Helpers for `observable` lists.
Expand Down

0 comments on commit e045696

Please sign in to comment.