Skip to content

Commit

Permalink
Adds a transform that will return YES if the value is equal to equalV…
Browse files Browse the repository at this point in the history
…alue, NO otherwise
  • Loading branch information
mirion authored and dcporter committed Feb 14, 2014
1 parent acd6478 commit 0d19769
Showing 1 changed file with 29 additions and 0 deletions.
29 changes: 29 additions & 0 deletions frameworks/runtime/system/binding.js
Expand Up @@ -1145,6 +1145,35 @@ SC.Binding = /** @scope SC.Binding.prototype */{
return this._logicGateBinding(this._LogicGateOr, pathA, pathB); return this._logicGateBinding(this._LogicGateOr, pathA, pathB);
}, },


/**
Adds a transform that will return YES if the value is equal to equalValue, NO otherwise
Usage examples:
...
isVisibleBinding: SC.Binding.equalTo( "myController.someValue", A_CONSTANT )
...
The transform can also be invoked using a single parameter, the value to compare with
...
isVisibleBinding: SC.Binding.oneWay( "myController.someValue" ).equalTo( A_CONSTANT )
...
@param {String} fromPath from path or null
@param {Object} equalValue the value to compare with
@returns {SC.Binding} this
*/
equalTo: function(fromPath, equalValue) {
// if the equalValue parameter is not provided, than compare the value with the 1st parameter
if (equalValue === undefined) {
equalValue = fromPath;
fromPath = null;
}

return this.from(fromPath).transform(function(value, binding) {
return value === equalValue;
});
},

toString: function () { toString: function () {
var from = this._fromRoot ? "<%@>:%@".fmt(this._fromRoot, this._fromPropertyPath) : this._fromPropertyPath; var from = this._fromRoot ? "<%@>:%@".fmt(this._fromRoot, this._fromPropertyPath) : this._fromPropertyPath;


Expand Down

0 comments on commit 0d19769

Please sign in to comment.