Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Adds a transform that will return YES if the value is equal to equalV…

…alue, NO otherwise
  • Loading branch information...
commit 0d1976955d2fa9b87f8122b593e1bb8716f863c7 1 parent acd6478
@mirion mirion authored dcporter committed
Showing with 29 additions and 0 deletions.
  1. +29 −0 frameworks/runtime/system/binding.js
View
29 frameworks/runtime/system/binding.js
@@ -1145,6 +1145,35 @@ SC.Binding = /** @scope SC.Binding.prototype */{
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 () {
var from = this._fromRoot ? "<%@>:%@".fmt(this._fromRoot, this._fromPropertyPath) : this._fromPropertyPath;
Please sign in to comment.
Something went wrong with that request. Please try again.