Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Update README.md

  • Loading branch information...
commit a7a0772520204533c7657ecc722eff14ab66db24 1 parent b46b2fc
@kmalakoff kmalakoff authored
Showing with 19 additions and 1 deletion.
  1. +19 −1 README.md
View
20 README.md
@@ -223,7 +223,9 @@ model = new Backbone.Model({first: 'Ringo', last: 'Starr'})
view_model = new ContactViewModelFullName(model)
equal(view_model.full_name(), 'Last: Starr, First: Ringo', "full name is good")
+# use a complex formatted string to set multiple attributes at once
view_model.full_name('Last: The Starr, First: Ringo')
+
equal(view_model.full_name(), 'Last: The Starr, First: Ringo', "full name is good")
equal(model.get('first'), 'Ringo', "first name is good")
equal(model.get('last'), 'The Starr', "last name is good")
@@ -313,7 +315,7 @@ kb.vmRelease(view_model_instance)
kb.vmRelease(view_model)
```
-Stub out an observable if you are not sure it will be in the model (so if/when it does arrive, the observing had already been established):
+Stub out an observable if you are not sure if specific attributes will be in the model. If/when the attributes do arrive, the observing had already been established reducing conditional checks.
```coffeescript
class ContactViewModelFullName extends kb.ViewModel
@@ -329,6 +331,16 @@ model.set({first: 'Ringo', last: 'Starr'})
equal(view_model.full_name(), 'Last: Starr, First: Ringo', "full name is good")
```
+Reassign (and stub out) specific defaut observable names to _{name} if you plan to use them only as internal, intermediate values. This way you can use your attribute names with advanced logic in your template bindings.
+
+```coffeescript
+class ContactViewModel extends kb.ViewModel
+ constructor: (model) ->
+ super(model, {internals: ['email', 'date']})
+ @email = kb.defaultWrapper(@_email, 'your.name@yourplace.com')
+ @date = new LongDateLocalizer(@_date)
+````
+
Knockback.defaultWrapper
-----------------------------
@@ -339,6 +351,12 @@ class ContactViewModel extends kb.ViewModel
constructor: (model) ->
super(model, {internals: ['email']})
@email = kb.defaultWrapper(@_email, 'your.name@yourplace.com')
+
+view_model = new ContactViewModel(model)
+...
+view_model.email.setToDefault()
+# or
+kb.vmSetToDefault(view_model)
```
Final notes
Please sign in to comment.
Something went wrong with that request. Please try again.