Skip to content
Toggle navigation
Toggle navigation
This project
Loading...
Sign in
brainfood
/
rivets
Go to a project
Toggle navigation
Toggle navigation pinning
Projects
Groups
Snippets
Help
Project
Activity
Repository
Graphs
Network
Create a new issue
Commits
Issue Boards
Files
Commits
Network
Compare
Branches
Tags
8db554cd
authored
2013-04-26 20:34:49 -0700
by
Michael Richards
Browse Files
Options
Browse Files
Tag
Download
Plain Diff
Merge pull request #154 from mikeric/view-context-updating
View context updating
2 parents
86b99ab0
01c164b5
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
20 additions
and
9 deletions
src/rivets.coffee
src/rivets.coffee
View file @
8db554c
...
...
@@ -14,7 +14,7 @@ class Rivets.Binding
# All information about the binding is passed into the constructor; the
# containing view, the DOM node, the type of binding, the model object and the
# keypath at which to listen for changes.
constructor
:
(
@
view
,
@
el
,
@
type
,
@
model
,
@
keypath
,
@
options
=
{})
->
constructor
:
(
@
view
,
@
el
,
@
type
,
@
key
,
@
keypath
,
@
options
=
{})
->
unless
@
binder
=
@
view
.
binders
[
type
]
for
identifier
,
value
of
@
view
.
binders
if
identifier
isnt
'*'
and
identifier
.
indexOf
(
'*'
)
isnt
-
1
...
...
@@ -25,11 +25,9 @@ class Rivets.Binding
@
args
.
shift
()
@
binder
or=
@
view
.
binders
[
'*'
]
if
@
binder
instanceof
Function
@
binder
=
{
routine
:
@
binder
}
@
binder
=
{
routine
:
@
binder
}
if
@
binder
instanceof
Function
@
formatters
=
@
options
.
formatters
||
[]
@
model
=
@
view
.
models
[
@
key
]
# Applies all the current formatters to the supplied value and returns the
# formatted value.
...
...
@@ -125,6 +123,13 @@ class Rivets.Binding
@
view
.
config
.
adapter
.
unsubscribe
model
,
keypath
,
@
sync
# Updates the binding's model from what is currently set on the view. Unbinds
# the old model first and then re-binds with the new model.
update
:
=>
@
unbind
()
@
model
=
@
view
.
models
[
@
key
]
@
bind
()
# A collection of bindings built from a set of parent elements.
class
Rivets
.
View
# The DOM elements and the model objects for binding are passed into the
...
...
@@ -182,17 +187,17 @@ class Rivets.View
options
.
formatters
=
pipes
options
.
bypass
=
path
.
indexOf
(
':'
)
!=
-
1
if
splitPath
[
0
]
model
=
@
models
[
splitPath
.
shift
()]
key
=
splitPath
.
shift
()
else
model
=
@
models
key
=
null
splitPath
.
shift
()
keypath
=
splitPath
.
join
'.'
if
model
if
@
models
[
key
]
?
if
dependencies
=
context
.
shift
()
options
.
dependencies
=
dependencies
.
split
/\s+/
@
bindings
.
push
new
Rivets
.
Binding
@
,
node
,
type
,
model
,
keypath
,
options
@
bindings
.
push
new
Rivets
.
Binding
@
,
node
,
type
,
key
,
keypath
,
options
attributes
=
null
if
attributes
...
...
@@ -224,6 +229,12 @@ class Rivets.View
publish
:
=>
binding
.
publish
()
for
binding
in
@
select
(
b
)
->
b
.
binder
.
publishes
# Updates the view's models along with any affected bindings.
update
:
(
models
=
{})
=>
for
key
,
model
of
models
@
models
[
key
]
=
model
binding
.
update
()
for
binding
in
@
select
(
b
)
->
b
.
key
is
key
# Cross-browser event binding.
bindEvent
=
(
el
,
event
,
handler
,
context
)
->
fn
=
(
e
)
->
handler
.
call
context
,
e
...
...
Please
register
or
sign in
to post a comment