Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Fixed three bugs in Bindings examples.

- Property didn't work because it didn't have Binding in the name.
- The name of the property didn't match how it was being accessed.
- It wasn't clear that the runloop must run between setting and getting.
  • Loading branch information...
commit 163a3f3ca751f32ba4a9e5ccff9a6f17d6e53a45 1 parent 679eca1
@apike apike authored wagenet committed
Showing with 20 additions and 14 deletions.
  1. +20 −14 source/core_concepts.textile
View
34 source/core_concepts.textile
@@ -381,13 +381,19 @@ MyApp.userController = SC.Object.create({
});
MyApp.mainView = SC.View.create({
- currentUserName: SC.Binding.from('MyApp.userController.name')
+ userBinding: SC.Binding.from('MyApp.userController.name')
});
MyApp.userController.set('name', 'Joe');
-MyApp.mainView.get('name'); // Joe
-MyApp.mainView.set('name', 'Jim');
-MyApp.userController.get('name'); // Jim
+
+// The runloop must run
+
+console.log(MyApp.mainView.get('user')); // Joe
+MyApp.mainView.set('user', 'Jim');
+
+// The runloop must run
+
+console.log(MyApp.userController.get('name')); // Jim
</javascript>
In this example, we used the absolute path to the property. Bindings
@@ -400,6 +406,16 @@ instead. In this case the local property (where the binding is defined) will
be updated when the remote property changes, but changes to the local
property will not propagate to the remote property.
+h4. Bindings Shorthand
+
+Since simple bindings are used so often, there's also a shortcut to creating
+bindings. All you need to do is append +Binding+ to the property name.
+In the above example, you could instead do:
+
+<javascript>
+userBinding: 'MyApp.userController.name'
+</javascript>
+
h4. Bindings and Chained Property Paths
Since bindings make use of observers behind the scenes, the same principles
@@ -421,16 +437,6 @@ MyApp.userNameView = SC.LabelView.create({
Since we used an asterisk in the +valueBinding+ property path, the binding
will be updated if either +mainUser+ or +mainUser.name+ changes.
-h4. Bindings Shorthand
-
-Since bindings are used so often, there's also a shortcut to creating
-bindings. All you need to do is append +Binding+ to the property name.
-In the above example, you could instead do:
-
-<javascript>
-currentUserNameBinding: 'MyApp.userController.name'
-</javascript>
-
h3. The Run Loop
Let me begin by saying that you will rarely have to reference the Run Loop
Please sign in to comment.
Something went wrong with that request. Please try again.