9d7e2c23 by Adam Heath

Allow binders to specify a 'tokenizes' flag; when true, rivets will do

nothing at all with keypath, and it look into the model at all to fetch
the value.  It will not do any change support for the keypath either.
This allows the binder to do something completely different with the
attribute value.  This can be access by way of this.keypath.
1 parent 46dbe672
...@@ -82,6 +82,7 @@ class Rivets.Binding ...@@ -82,6 +82,7 @@ class Rivets.Binding
82 82
83 # Publishes the value currently set on the input element back to the model. 83 # Publishes the value currently set on the input element back to the model.
84 publish: => 84 publish: =>
85 return if @binder.tokenizes
85 value = getInputValue @el 86 value = getInputValue @el
86 87
87 for formatter in @formatters.slice(0).reverse() 88 for formatter in @formatters.slice(0).reverse()
...@@ -103,7 +104,7 @@ class Rivets.Binding ...@@ -103,7 +104,7 @@ class Rivets.Binding
103 if @options.bypass 104 if @options.bypass
104 @sync() 105 @sync()
105 else 106 else
106 Rivets.config.adapter.subscribe @model, @keypath, @sync if @keypath 107 Rivets.config.adapter.subscribe @model, @keypath, @sync if @keypath and !@binder.tokenizes
107 @sync() if Rivets.config.preloadData 108 @sync() if Rivets.config.preloadData
108 109
109 loopDeps @, (model, keypath) => Rivets.config.adapter.subscribe model, keypath, @sync 110 loopDeps @, (model, keypath) => Rivets.config.adapter.subscribe model, keypath, @sync
...@@ -112,7 +113,7 @@ class Rivets.Binding ...@@ -112,7 +113,7 @@ class Rivets.Binding
112 unbind: => 113 unbind: =>
113 @binder.unbind?.call @, @el 114 @binder.unbind?.call @, @el
114 115
115 unless @options.bypass 116 unless @options.bypass or !@binder.tokenizes
116 Rivets.config.adapter.unsubscribe @model, @keypath, @sync if @keypath 117 Rivets.config.adapter.unsubscribe @model, @keypath, @sync if @keypath
117 118
118 loopDeps @, (model, keypath) => Rivets.config.adapter.unsubscribe model, keypath, @sync 119 loopDeps @, (model, keypath) => Rivets.config.adapter.unsubscribe model, keypath, @sync
...@@ -187,18 +188,20 @@ defaultExpressionParser = (view, node, type, models, value) -> ...@@ -187,18 +188,20 @@ defaultExpressionParser = (view, node, type, models, value) ->
187 bypass: path.indexOf(':') != -1 188 bypass: path.indexOf(':') != -1
188 bindContext: models 189 bindContext: models
189 parsingSupport = Rivets.config.adapter.parsingSupport 190 parsingSupport = Rivets.config.adapter.parsingSupport
190 [options.binder, options.args] = findBinder type 191 [binder, options.args] = findBinder type
191 firstPart = if parsingSupport 192 binderTokenizes = binder.tokenizes
193 options.binder = binder
194 firstPart = if parsingSupport or binderTokenizes
192 splitPath[0] 195 splitPath[0]
193 else 196 else
194 splitPath.shift() 197 splitPath.shift()
195 model = if firstPart 198 model = if firstPart or !binderTokenizes
196 Rivets.config.adapter.read models, firstPart 199 Rivets.config.adapter.read models, firstPart
197 else 200 else
198 models 201 models
199 keypath = splitPath.join '.' 202 keypath = splitPath.join '.'
200 203
201 if model 204 if model or binderTokenizes
202 if dependencies = context.shift() 205 if dependencies = context.shift()
203 options.dependencies = dependencies.split /\s+/ 206 options.dependencies = dependencies.split /\s+/
204 207
......