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
1e6b3edf
authored
2012-09-03 14:11:47 -0700
by
Michael Richards
Browse Files
Options
Browse Files
Tag
Download
Email Patches
Plain Diff
Build 0.3.6.
1 parent
078497e0
Expand all
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
73 additions
and
27 deletions
lib/rivets.js
lib/rivets.min.js
package.json
src/rivets.coffee
lib/rivets.js
View file @
1e6b3ed
// rivets.js
// version: 0.3.
5
// version: 0.3.
6
// author: Michael Richards
// license: MIT
(
function
()
{
...
...
@@ -26,14 +26,18 @@
this
.
options
=
options
!=
null
?
options
:
{};
this
.
unbind
=
__bind
(
this
.
unbind
,
this
);
this
.
bind
=
__bind
(
this
.
bind
,
this
);
this
.
publish
=
__bind
(
this
.
publish
,
this
);
this
.
bind
=
__bind
(
this
.
bind
,
this
);
this
.
sync
=
__bind
(
this
.
sync
,
this
);
this
.
set
=
__bind
(
this
.
set
,
this
);
this
.
formattedValue
=
__bind
(
this
.
formattedValue
,
this
);
this
.
isBidirectional
=
__bind
(
this
.
isBidirectional
,
this
);
this
.
routine
=
(
function
()
{
switch
(
this
.
options
.
special
)
{
case
"event"
:
...
...
@@ -49,7 +53,10 @@
this
.
formatters
=
this
.
options
.
formatters
||
[];
}
Binding
.
prototype
.
bidirectionals
=
[
'value'
,
'checked'
,
'unchecked'
];
Binding
.
prototype
.
isBidirectional
=
function
()
{
var
_ref
;
return
(
_ref
=
this
.
type
)
===
'value'
||
_ref
===
'checked'
||
_ref
===
'unchecked'
;
};
Binding
.
prototype
.
formattedValue
=
function
(
value
)
{
var
args
,
formatter
,
id
,
_i
,
_len
,
_ref
,
_ref1
,
_ref2
;
...
...
@@ -75,52 +82,48 @@
}
};
Binding
.
prototype
.
sync
=
function
()
{
return
this
.
set
(
this
.
options
.
bypass
?
this
.
model
[
this
.
keypath
]
:
Rivets
.
config
.
adapter
.
read
(
this
.
model
,
this
.
keypath
));
};
Binding
.
prototype
.
publish
=
function
()
{
return
Rivets
.
config
.
adapter
.
publish
(
this
.
model
,
this
.
keypath
,
getInputValue
(
this
.
el
));
};
Binding
.
prototype
.
bind
=
function
()
{
var
callback
,
keypath
,
_i
,
_len
,
_ref
,
_ref1
,
_ref2
,
_this
=
this
;
var
keypath
,
_i
,
_len
,
_ref
,
_ref1
;
if
(
this
.
options
.
bypass
)
{
this
.
s
et
(
this
.
model
[
this
.
keypath
]
);
this
.
s
ync
(
);
}
else
{
Rivets
.
config
.
adapter
.
subscribe
(
this
.
model
,
this
.
keypath
,
this
.
s
et
);
Rivets
.
config
.
adapter
.
subscribe
(
this
.
model
,
this
.
keypath
,
this
.
s
ync
);
if
(
Rivets
.
config
.
preloadData
)
{
this
.
s
et
(
Rivets
.
config
.
adapter
.
read
(
this
.
model
,
this
.
keypath
)
);
this
.
s
ync
(
);
}
}
if
((
_ref
=
this
.
options
.
dependencies
)
!=
null
?
_ref
.
length
:
void
0
)
{
this
.
dependencyCallbacks
=
{};
_ref1
=
this
.
options
.
dependencies
;
for
(
_i
=
0
,
_len
=
_ref1
.
length
;
_i
<
_len
;
_i
++
)
{
keypath
=
_ref1
[
_i
];
callback
=
this
.
dependencyCallbacks
[
keypath
]
=
function
(
value
)
{
return
_this
.
set
(
_this
.
options
.
bypass
?
_this
.
model
[
_this
.
keypath
]
:
Rivets
.
config
.
adapter
.
read
(
_this
.
model
,
_this
.
keypath
));
};
Rivets
.
config
.
adapter
.
subscribe
(
this
.
model
,
keypath
,
callback
);
Rivets
.
config
.
adapter
.
subscribe
(
this
.
model
,
keypath
,
this
.
sync
);
}
}
if
(
_ref2
=
this
.
type
,
__indexOf
.
call
(
this
.
bidirectionals
,
_ref2
)
>=
0
)
{
if
(
this
.
isBidirectional
()
)
{
return
bindEvent
(
this
.
el
,
'change'
,
this
.
publish
);
}
};
Binding
.
prototype
.
publish
=
function
(
e
)
{
var
el
;
el
=
e
.
target
||
e
.
srcElement
;
return
Rivets
.
config
.
adapter
.
publish
(
this
.
model
,
this
.
keypath
,
getInputValue
(
el
));
};
Binding
.
prototype
.
unbind
=
function
()
{
var
callback
,
keypath
,
_i
,
_len
,
_ref
,
_ref1
,
_ref2
;
var
keypath
,
_i
,
_len
,
_ref
,
_ref1
;
if
(
!
this
.
options
.
bypass
)
{
Rivets
.
config
.
adapter
.
unsubscribe
(
this
.
model
,
this
.
keypath
,
this
.
s
et
);
Rivets
.
config
.
adapter
.
unsubscribe
(
this
.
model
,
this
.
keypath
,
this
.
s
ync
);
if
((
_ref
=
this
.
options
.
dependencies
)
!=
null
?
_ref
.
length
:
void
0
)
{
_ref1
=
this
.
options
.
dependencies
;
for
(
_i
=
0
,
_len
=
_ref1
.
length
;
_i
<
_len
;
_i
++
)
{
keypath
=
_ref1
[
_i
];
callback
=
this
.
dependencyCallbacks
[
keypath
];
Rivets
.
config
.
adapter
.
unsubscribe
(
this
.
model
,
keypath
,
callback
);
Rivets
.
config
.
adapter
.
unsubscribe
(
this
.
model
,
keypath
,
this
.
sync
);
}
}
if
(
_ref2
=
this
.
type
,
__indexOf
.
call
(
this
.
bidirectionals
,
_ref2
)
>=
0
)
{
if
(
this
.
isBidirectional
()
)
{
return
this
.
el
.
removeEventListener
(
'change'
,
this
.
publish
);
}
}
...
...
@@ -135,10 +138,16 @@
function
View
(
els
,
models
)
{
this
.
els
=
els
;
this
.
models
=
models
;
this
.
publish
=
__bind
(
this
.
publish
,
this
);
this
.
sync
=
__bind
(
this
.
sync
,
this
);
this
.
unbind
=
__bind
(
this
.
unbind
,
this
);
this
.
bind
=
__bind
(
this
.
bind
,
this
);
this
.
select
=
__bind
(
this
.
select
,
this
);
this
.
build
=
__bind
(
this
.
build
,
this
);
this
.
bindingRegExp
=
__bind
(
this
.
bindingRegExp
,
this
);
...
...
@@ -264,6 +273,19 @@
}
};
View
.
prototype
.
select
=
function
(
fn
)
{
var
binding
,
_i
,
_len
,
_ref
,
_results
;
_ref
=
this
.
bindings
;
_results
=
[];
for
(
_i
=
0
,
_len
=
_ref
.
length
;
_i
<
_len
;
_i
++
)
{
binding
=
_ref
[
_i
];
if
(
fn
(
binding
))
{
_results
.
push
(
binding
);
}
}
return
_results
;
};
View
.
prototype
.
bind
=
function
()
{
var
binding
,
_i
,
_len
,
_ref
,
_results
;
_ref
=
this
.
bindings
;
...
...
@@ -286,6 +308,30 @@
return
_results
;
};
View
.
prototype
.
sync
=
function
()
{
var
binding
,
_i
,
_len
,
_ref
,
_results
;
_ref
=
this
.
bindings
;
_results
=
[];
for
(
_i
=
0
,
_len
=
_ref
.
length
;
_i
<
_len
;
_i
++
)
{
binding
=
_ref
[
_i
];
_results
.
push
(
binding
.
sync
());
}
return
_results
;
};
View
.
prototype
.
publish
=
function
()
{
var
binding
,
_i
,
_len
,
_ref
,
_results
;
_ref
=
this
.
select
(
function
(
b
)
{
return
b
.
isBidirectional
();
});
_results
=
[];
for
(
_i
=
0
,
_len
=
_ref
.
length
;
_i
<
_len
;
_i
++
)
{
binding
=
_ref
[
_i
];
_results
.
push
(
binding
.
publish
());
}
return
_results
;
};
return
View
;
})();
...
...
lib/rivets.min.js
View file @
1e6b3ed
This diff is collapsed.
Click to expand it.
package.json
View file @
1e6b3ed
{
"name"
:
"rivets"
,
"description"
:
"Declarative data binding facility."
,
"version"
:
"0.3.
5
"
,
"version"
:
"0.3.
6
"
,
"author"
:
"Michael Richards"
,
"url"
:
"http://rivetsjs.com"
,
"main"
:
"./lib/rivets.js"
,
...
...
src/rivets.coffee
View file @
1e6b3ed
# rivets.js
# version : 0.3.
5
# version : 0.3.
6
# author : Michael Richards
# license : MIT
...
...
Please
register
or
sign in
to post a comment