Make all bindings hold reference to the actual key at which the model resides on the view.
This allows us to update the bindings' model property according to the models currently set on the view.
Showing
1 changed file
with
7 additions
and
9 deletions
... | @@ -14,7 +14,7 @@ class Rivets.Binding | ... | @@ -14,7 +14,7 @@ class Rivets.Binding |
14 | # All information about the binding is passed into the constructor; the | 14 | # All information about the binding is passed into the constructor; the |
15 | # containing view, the DOM node, the type of binding, the model object and the | 15 | # containing view, the DOM node, the type of binding, the model object and the |
16 | # keypath at which to listen for changes. | 16 | # keypath at which to listen for changes. |
17 | constructor: (@view, @el, @type, @model, @keypath, @options = {}) -> | 17 | constructor: (@view, @el, @type, @key, @keypath, @options = {}) -> |
18 | unless @binder = @view.binders[type] | 18 | unless @binder = @view.binders[type] |
19 | for identifier, value of @view.binders | 19 | for identifier, value of @view.binders |
20 | if identifier isnt '*' and identifier.indexOf('*') isnt -1 | 20 | if identifier isnt '*' and identifier.indexOf('*') isnt -1 |
... | @@ -25,11 +25,9 @@ class Rivets.Binding | ... | @@ -25,11 +25,9 @@ class Rivets.Binding |
25 | @args.shift() | 25 | @args.shift() |
26 | 26 | ||
27 | @binder or= @view.binders['*'] | 27 | @binder or= @view.binders['*'] |
28 | 28 | @binder = {routine: @binder} if @binder instanceof Function | |
29 | if @binder instanceof Function | ||
30 | @binder = {routine: @binder} | ||
31 | |||
32 | @formatters = @options.formatters || [] | 29 | @formatters = @options.formatters || [] |
30 | @model = @view.models[@key] | ||
33 | 31 | ||
34 | # Applies all the current formatters to the supplied value and returns the | 32 | # Applies all the current formatters to the supplied value and returns the |
35 | # formatted value. | 33 | # formatted value. |
... | @@ -182,17 +180,17 @@ class Rivets.View | ... | @@ -182,17 +180,17 @@ class Rivets.View |
182 | options.formatters = pipes | 180 | options.formatters = pipes |
183 | options.bypass = path.indexOf(':') != -1 | 181 | options.bypass = path.indexOf(':') != -1 |
184 | if splitPath[0] | 182 | if splitPath[0] |
185 | model = @models[splitPath.shift()] | 183 | key = splitPath.shift() |
186 | else | 184 | else |
187 | model = @models | 185 | key = null |
188 | splitPath.shift() | 186 | splitPath.shift() |
189 | keypath = splitPath.join '.' | 187 | keypath = splitPath.join '.' |
190 | 188 | ||
191 | if model | 189 | if @models[key]? |
192 | if dependencies = context.shift() | 190 | if dependencies = context.shift() |
193 | options.dependencies = dependencies.split /\s+/ | 191 | options.dependencies = dependencies.split /\s+/ |
194 | 192 | ||
195 | @bindings.push new Rivets.Binding @, node, type, model, keypath, options | 193 | @bindings.push new Rivets.Binding @, node, type, key, keypath, options |
196 | 194 | ||
197 | attributes = null if attributes | 195 | attributes = null if attributes |
198 | 196 | ... | ... |
-
Please register or sign in to post a comment