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
8ef7c842
authored
2012-06-30 16:58:10 -0700
by
Michael Richards
Browse Files
Options
Browse Files
Tag
Download
Email Patches
Plain Diff
Build a queue of bindings and perform the binding routines after parsing. [Closes #3]
1 parent
d06e350d
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
24 additions
and
25 deletions
lib/rivets.js
src/rivets.coffee
lib/rivets.js
View file @
8ef7c84
...
...
@@ -35,7 +35,7 @@
Binding
.
prototype
.
bind
=
function
()
{
var
_ref
,
_this
=
this
;
this
.
adapter
.
subscribe
(
this
.
context
,
this
.
keypath
,
function
(
value
)
{
this
.
set
()
&&
this
.
adapter
.
subscribe
(
this
.
context
,
this
.
keypath
,
function
(
value
)
{
return
_this
.
set
(
value
);
});
if
(
_ref
=
this
.
type
,
__indexOf
.
call
(
Rivets
.
bidirectionals
,
_ref
)
>=
0
)
{
...
...
@@ -114,35 +114,31 @@
return
Rivets
.
bindings
[
routine
]
=
routineFunction
;
},
bind
:
function
(
el
,
adapter
,
contexts
)
{
var
attribute
,
binding
,
context
,
keypath
,
node
,
path
,
type
,
_i
,
_len
,
_ref
,
_results
;
var
attribute
,
binding
,
bindings
,
context
,
keypath
,
node
,
path
,
type
,
_i
,
_j
,
_k
,
_len
,
_len1
,
_len2
,
_ref
,
_ref1
;
if
(
contexts
==
null
)
{
contexts
=
{};
}
bindings
=
[];
_ref
=
el
.
getElementsByTagName
(
'*'
);
_results
=
[];
for
(
_i
=
0
,
_len
=
_ref
.
length
;
_i
<
_len
;
_i
++
)
{
node
=
_ref
[
_i
];
_results
.
push
((
function
()
{
var
_j
,
_len1
,
_ref1
,
_results1
;
_ref1
=
node
.
attributes
;
_results1
=
[];
for
(
_j
=
0
,
_len1
=
_ref1
.
length
;
_j
<
_len1
;
_j
++
)
{
attribute
=
_ref1
[
_j
];
if
(
/^data-/
.
test
(
attribute
.
name
))
{
type
=
attribute
.
name
.
replace
(
'data-'
,
''
);
path
=
attribute
.
value
.
split
(
'.'
);
context
=
path
.
shift
();
keypath
=
path
.
join
(
'.'
);
binding
=
new
Rivets
.
Binding
(
node
,
adapter
,
type
,
contexts
[
context
],
keypath
);
_results1
.
push
(
binding
.
bind
());
}
else
{
_results1
.
push
(
void
0
);
}
_ref1
=
node
.
attributes
;
for
(
_j
=
0
,
_len1
=
_ref1
.
length
;
_j
<
_len1
;
_j
++
)
{
attribute
=
_ref1
[
_j
];
if
(
/^data-/
.
test
(
attribute
.
name
))
{
type
=
attribute
.
name
.
replace
(
'data-'
,
''
);
path
=
attribute
.
value
.
split
(
'.'
);
context
=
path
.
shift
();
keypath
=
path
.
join
(
'.'
);
bindings
.
push
(
new
Rivets
.
Binding
(
node
,
adapter
,
type
,
contexts
[
context
],
keypath
));
}
return
_results1
;
})());
}
}
return
_results
;
for
(
_k
=
0
,
_len2
=
bindings
.
length
;
_k
<
_len2
;
_k
++
)
{
binding
=
bindings
[
_k
];
binding
.
bind
();
}
return
bindings
.
length
;
}
};
...
...
src/rivets.coffee
View file @
8ef7c84
...
...
@@ -19,7 +19,7 @@ class Rivets.Binding
# Conditionally also does the inverse and listens to the element for changes
# to propogate back to the context object.
bind
:
=>
@
adapter
.
subscribe
@
context
,
@
keypath
,
(
value
)
=>
@
set
value
@
set
()
and
@
adapter
.
subscribe
@
context
,
@
keypath
,
(
value
)
=>
@
set
value
if
@
type
in
Rivets
.
bidirectionals
@
el
.
addEventListener
'change'
,
(
el
)
=>
...
...
@@ -79,6 +79,8 @@ Rivets.interface =
Rivets
.
bindings
[
routine
]
=
routineFunction
bind
:
(
el
,
adapter
,
contexts
=
{})
->
bindings
=
[]
for
node
in
el
.
getElementsByTagName
'*'
for
attribute
in
node
.
attributes
if
/^data-/
.
test
attribute
.
name
...
...
@@ -86,9 +88,10 @@ Rivets.interface =
path
=
attribute
.
value
.
split
'.'
context
=
path
.
shift
()
keypath
=
path
.
join
'.'
bindings
.
push
new
Rivets
.
Binding
node
,
adapter
,
type
,
contexts
[
context
],
keypath
binding
=
new
Rivets
.
Binding
node
,
adapter
,
type
,
contexts
[
context
],
keypath
binding
.
bind
()
binding
.
bind
()
for
binding
in
bindings
bindings
.
length
# Exports rivets for both CommonJS and the browser.
if
module
?
...
...
Please
register
or
sign in
to post a comment