Skip to content

Commit

Permalink
Write hooks can change the return value of the writer by returning a …
Browse files Browse the repository at this point in the history
…value themselves
  • Loading branch information
nathansobo committed Jan 10, 2011
1 parent 4c7c5e9 commit 1437aa5
Showing 1 changed file with 5 additions and 3 deletions.
8 changes: 5 additions & 3 deletions lib/monarch/foundation.js
Original file line number Diff line number Diff line change
Expand Up @@ -149,9 +149,11 @@ function buildPropertyAccessor(name, reader, writer, afterWriteHook, afterChange
} else {
var oldValue = this[fieldName];
var newValue = writer.apply(this, arguments) || this[fieldName];
if (afterWriteHook) afterWriteHook.call(this, newValue, oldValue);
if (afterChangeHook && newValue !== oldValue) afterChangeHook.call(this, newValue, oldValue);
return newValue;

var writeHookReturnVal, changeHookReturnVal;
if (afterWriteHook) writeHookReturnVal = afterWriteHook.call(this, newValue, oldValue);
if (afterChangeHook && newValue !== oldValue) changeHookReturnVal = afterChangeHook.call(this, newValue, oldValue);
return changeHookReturnVal || writeHookReturnVal || newValue;
}
};
accessor._accessor_ = true;
Expand Down

0 comments on commit 1437aa5

Please sign in to comment.