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
5b1195cc
authored
2012-07-01 00:27:15 -0700
by
Michael Richards
Browse Files
Options
Browse Files
Tag
Download
Email Patches
Plain Diff
Make adapter part of the configuration instead of an argument for rivets.bind.
1 parent
fb5ebc1a
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
12 additions
and
13 deletions
lib/rivets.js
src/rivets.coffee
lib/rivets.js
View file @
5b1195c
...
...
@@ -10,9 +10,8 @@
Binding
.
name
=
'Binding'
;
function
Binding
(
el
,
adapter
,
type
,
context
,
keypath
)
{
function
Binding
(
el
,
type
,
context
,
keypath
)
{
this
.
el
=
el
;
this
.
adapter
=
adapter
;
this
.
type
=
type
;
this
.
context
=
context
;
this
.
keypath
=
keypath
;
...
...
@@ -27,7 +26,7 @@
if
(
value
==
null
)
{
value
=
null
;
}
return
this
.
routine
(
this
.
el
,
value
||
this
.
adapter
.
read
(
this
.
context
,
this
.
keypath
));
return
this
.
routine
(
this
.
el
,
value
||
Rivets
.
config
.
adapter
.
read
(
this
.
context
,
this
.
keypath
));
};
Binding
.
prototype
.
bind
=
function
()
{
...
...
@@ -36,12 +35,12 @@
if
(
Rivets
.
config
.
preloadData
)
{
this
.
set
();
}
this
.
adapter
.
subscribe
(
this
.
context
,
this
.
keypath
,
function
(
value
)
{
Rivets
.
config
.
adapter
.
subscribe
(
this
.
context
,
this
.
keypath
,
function
(
value
)
{
return
_this
.
set
(
value
);
});
if
(
_ref
=
this
.
type
,
__indexOf
.
call
(
bidirectionals
,
_ref
)
>=
0
)
{
return
this
.
el
.
addEventListener
(
'change'
,
function
(
el
)
{
return
_this
.
adapter
.
publish
(
_this
.
context
,
_this
.
keypath
,
getInputValue
(
el
));
return
Rivets
.
config
.
adapter
.
publish
(
_this
.
context
,
_this
.
keypath
,
getInputValue
(
el
));
});
}
};
...
...
@@ -130,7 +129,7 @@
register
:
function
(
routine
,
routineFunction
)
{
return
Rivets
.
bindings
[
routine
]
=
routineFunction
;
},
bind
:
function
(
el
,
adapter
,
contexts
)
{
bind
:
function
(
el
,
contexts
)
{
var
attribute
,
binding
,
bindings
,
context
,
keypath
,
node
,
path
,
type
,
_i
,
_j
,
_k
,
_len
,
_len1
,
_len2
,
_ref
,
_ref1
;
if
(
contexts
==
null
)
{
contexts
=
{};
...
...
@@ -147,7 +146,7 @@
path
=
attribute
.
value
.
split
(
'.'
);
context
=
path
.
shift
();
keypath
=
path
.
join
(
'.'
);
bindings
.
push
(
new
Rivets
.
Binding
(
node
,
adapter
,
type
,
contexts
[
context
],
keypath
));
bindings
.
push
(
new
Rivets
.
Binding
(
node
,
type
,
contexts
[
context
],
keypath
));
}
}
}
...
...
src/rivets.coffee
View file @
5b1195c
...
...
@@ -6,24 +6,24 @@
Rivets
=
{}
class
Rivets
.
Binding
constructor
:
(
@
el
,
@
adapter
,
@
type
,
@
context
,
@
keypath
)
->
constructor
:
(
@
el
,
@
type
,
@
context
,
@
keypath
)
->
@
routine
=
Rivets
.
bindings
[
@
type
]
||
attributeBinding
@
type
# Sets a value for this binding. Basically just runs the routine on the
# element with a suplied value.
set
:
(
value
=
null
)
=>
@
routine
@
el
,
value
||
@
adapter
.
read
@
context
,
@
keypath
@
routine
@
el
,
value
||
Rivets
.
config
.
adapter
.
read
@
context
,
@
keypath
# Subscribes to the context object for changes on the specific keypath.
# Conditionally also does the inverse and listens to the element for changes
# to propogate back to the context object.
bind
:
=>
@
set
()
if
Rivets
.
config
.
preloadData
@
adapter
.
subscribe
@
context
,
@
keypath
,
(
value
)
=>
@
set
value
Rivets
.
config
.
adapter
.
subscribe
@
context
,
@
keypath
,
(
value
)
=>
@
set
value
if
@
type
in
bidirectionals
@
el
.
addEventListener
'change'
,
(
el
)
=>
@
adapter
.
publish
@
context
,
@
keypath
,
getInputValue
el
Rivets
.
config
.
adapter
.
publish
@
context
,
@
keypath
,
getInputValue
el
# Returns the current input value for the specified element.
getInputValue
=
(
el
)
->
...
...
@@ -86,7 +86,7 @@ rivets =
register
:
(
routine
,
routineFunction
)
->
Rivets
.
bindings
[
routine
]
=
routineFunction
bind
:
(
el
,
adapter
,
contexts
=
{})
->
bind
:
(
el
,
contexts
=
{})
->
bindings
=
[]
for
node
in
el
.
getElementsByTagName
'*'
...
...
@@ -96,7 +96,7 @@ rivets =
path
=
attribute
.
value
.
split
'.'
context
=
path
.
shift
()
keypath
=
path
.
join
'.'
bindings
.
push
new
Rivets
.
Binding
node
,
adapter
,
type
,
contexts
[
context
],
keypath
bindings
.
push
new
Rivets
.
Binding
node
,
type
,
contexts
[
context
],
keypath
binding
.
bind
()
for
binding
in
bindings
bindings
.
length
...
...
Please
register
or
sign in
to post a comment