Implement Rivets.TextBinding to building text node bindings.
Showing
1 changed file
with
20 additions
and
0 deletions
... | @@ -207,6 +207,26 @@ class Rivets.ComponentBinding extends Rivets.Binding | ... | @@ -207,6 +207,26 @@ class Rivets.ComponentBinding extends Rivets.Binding |
207 | unbind: => | 207 | unbind: => |
208 | @componentView?.unbind() | 208 | @componentView?.unbind() |
209 | 209 | ||
210 | # Rivets.TextBinding | ||
211 | # ----------------------- | ||
212 | |||
213 | # A text node binding, defined internally to deal with text and element node | ||
214 | # differences while avoiding it being overwritten. | ||
215 | class Rivets.TextBinding extends Rivets.Binding | ||
216 | # Initializes a text binding for the specified view and text node. | ||
217 | constructor: (@view, @el, @type, @key, @keypath, @options = {}) -> | ||
218 | @formatters = @options.formatters || [] | ||
219 | @model = if @key then @view.models[@key] else @view.models | ||
220 | |||
221 | # A standard routine binder used for text node bindings. | ||
222 | binder: | ||
223 | routine: (node, value) -> | ||
224 | node.data = value ? '' | ||
225 | |||
226 | # Wrap the call to `sync` in fat-arrow to avoid function context issues. | ||
227 | sync: => | ||
228 | super | ||
229 | |||
210 | # Rivets.View | 230 | # Rivets.View |
211 | # ----------- | 231 | # ----------- |
212 | 232 | ... | ... |
-
Please register or sign in to post a comment