Created
October 14, 2010 03:13
-
-
Save ColinCampbell/625484 to your computer and use it in GitHub Desktop.
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
| From a7a64cf081f4cbf30371bdc0503a93636548910d Mon Sep 17 00:00:00 2001 | |
| From: Colin Campbell <[email protected]> | |
| Date: Wed, 13 Oct 2010 23:12:29 -0400 | |
| Subject: [PATCH] Allows for easier binding in the form of 'foo: SC.binding(...)' rather than fooBinding: '...' | |
| --- | |
| frameworks/runtime/system/object.js | 13 +++++++++ | |
| frameworks/runtime/tests/system/object/bindings.js | 28 ++++++++++++++++++++ | |
| 2 files changed, 41 insertions(+), 0 deletions(-) | |
| diff --git a/frameworks/runtime/system/object.js b/frameworks/runtime/system/object.js | |
| index 82be194..c3c5aa3 100644 | |
| --- a/frameworks/runtime/system/object.js | |
| +++ b/frameworks/runtime/system/object.js | |
| @@ -99,6 +99,19 @@ SC._object_extend = function _object_extend(base, ext) { | |
| if (bindings === null) bindings = (base._bindings || SC.EMPTY_ARRAY).slice(); | |
| bindings[bindings.length] = key ; | |
| + } else if (value && value.parentBinding !== undefined && (key.length < 14 || key.slice(-14) !== "BindingDefault")) { | |
| + if (!clonedBindings) { | |
| + bindings = (bindings || SC.EMPTY_ARRAY).slice() ; | |
| + clonedBindings = YES ; | |
| + } | |
| + | |
| + if (bindings === null) bindings = (base._bindings || SC.EMPTY_ARRAY).slice(); | |
| + | |
| + // nullify the base for this key, but add binding to [key]Binding property | |
| + base[key] = null; | |
| + | |
| + key += "Binding"; // the value of this key gets set at the bottom of this function | |
| + bindings[bindings.length] = key; | |
| // Also add observers, outlets, and properties for functions... | |
| } else if (value && (value instanceof Function)) { | |
| diff --git a/frameworks/runtime/tests/system/object/bindings.js b/frameworks/runtime/tests/system/object/bindings.js | |
| index 1daa4f4..577e1a3 100644 | |
| --- a/frameworks/runtime/tests/system/object/bindings.js | |
| +++ b/frameworks/runtime/tests/system/object/bindings.js | |
| @@ -164,6 +164,34 @@ test("fooBinding: .bar should bind to relative path", function() { | |
| equals("changedValue", testObject.get("foo"), "testObject.foo"); | |
| }); | |
| +test("foo: SC.binding('TestNamespace.fromObject.bar') should follow absolute path", function() { | |
| + // create binding | |
| + testObject = TestObject.create({ | |
| + foo: SC.binding("TestNamespace.fromObject.bar") | |
| + }) ; | |
| + SC.Binding.flushPendingChanges() ; // actually sets up up the binding | |
| + | |
| + // now make a change to see if the binding triggers. | |
| + fromObject.set("bar", "changedValue") ; | |
| + | |
| + SC.Binding.flushPendingChanges(); | |
| + equals("changedValue", testObject.get("foo"), "testObject.foo"); | |
| +}); | |
| + | |
| +test("foo: SC.binding('.bar') should bind to relative path", function() { | |
| + | |
| + testObject = TestObject.create({ | |
| + foo: SC.binding(".bar") | |
| + }) ; | |
| + SC.Binding.flushPendingChanges() ; // actually sets up up the binding | |
| + | |
| + // now make a change to see if the binding triggers. | |
| + testObject.set("bar", "changedValue") ; | |
| + | |
| + SC.Binding.flushPendingChanges(); | |
| + equals("changedValue", testObject.get("foo"), "testObject.foo"); | |
| +}); | |
| + | |
| test("fooBinding: SC.Binding.bool(TestNamespace.fromObject.bar should create binding with bool transform", function() { | |
| testObject = TestObject.create({ | |
| -- | |
| 1.7.1 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment