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
54ae655a
authored
2013-06-23 20:32:25 -0700
by
Michael Richards
Browse Files
Options
Browse Files
Tag
Download
Plain Diff
Merge branch 'master' into text-templates
2 parents
f7c291b5
dba47367
Expand all
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
93 additions
and
30 deletions
component.json
dist/rivets.js
dist/rivets.min.js
package.json
src/rivets.coffee
component.json
View file @
54ae655
...
...
@@ -2,7 +2,7 @@
"name"
:
"rivets"
,
"repo"
:
"mikeric/rivets"
,
"description"
:
"Declarative data binding facility."
,
"version"
:
"0.5.
7
"
,
"version"
:
"0.5.
8
"
,
"keywords"
:
[
"data binding"
,
"templating"
],
"scripts"
:
[
"dist/rivets.js"
],
"main"
:
"dist/rivets.js"
,
...
...
dist/rivets.js
View file @
54ae655
// Rivets.js
// version: 0.5.
7
// version: 0.5.
8
// author: Michael Richards
// license: MIT
(
function
()
{
...
...
@@ -173,10 +173,31 @@
}
};
Binding
.
prototype
.
update
=
function
()
{
this
.
unbind
();
this
.
model
=
this
.
key
?
this
.
view
.
models
[
this
.
key
]
:
this
.
view
.
models
;
return
this
.
bind
();
Binding
.
prototype
.
update
=
function
(
models
)
{
var
_ref
;
if
(
models
==
null
)
{
models
=
{};
}
if
(
this
.
key
)
{
if
(
models
[
this
.
key
])
{
if
(
!
this
.
options
.
bypass
)
{
this
.
view
.
config
.
adapter
.
unsubscribe
(
this
.
model
,
this
.
keypath
,
this
.
sync
);
}
this
.
model
=
models
[
this
.
key
];
if
(
this
.
options
.
bypass
)
{
this
.
sync
();
}
else
{
this
.
view
.
config
.
adapter
.
subscribe
(
this
.
model
,
this
.
keypath
,
this
.
sync
);
if
(
this
.
view
.
config
.
preloadData
)
{
this
.
sync
();
}
}
}
}
else
{
this
.
sync
();
}
return
(
_ref
=
this
.
binder
.
update
)
!=
null
?
_ref
.
call
(
this
,
models
)
:
void
0
;
};
return
Binding
;
...
...
@@ -404,28 +425,20 @@
};
View
.
prototype
.
update
=
function
(
models
)
{
var
binding
,
key
,
model
,
_results
;
var
binding
,
key
,
model
,
_
i
,
_len
,
_ref
,
_
results
;
if
(
models
==
null
)
{
models
=
{};
}
_results
=
[];
for
(
key
in
models
)
{
model
=
models
[
key
];
this
.
models
[
key
]
=
model
;
_results
.
push
((
function
()
{
var
_i
,
_len
,
_ref
,
_results1
;
_ref
=
this
.
select
(
function
(
b
)
{
return
b
.
key
===
key
;
});
_results1
=
[];
for
(
_i
=
0
,
_len
=
_ref
.
length
;
_i
<
_len
;
_i
++
)
{
binding
=
_ref
[
_i
];
_results1
.
push
(
binding
.
update
());
}
return
_results1
;
}).
call
(
this
));
}
_ref
=
this
.
bindings
;
_results
=
[];
for
(
_i
=
0
,
_len
=
_ref
.
length
;
_i
<
_len
;
_i
++
)
{
binding
=
_ref
[
_i
];
_results
.
push
(
binding
.
update
(
models
));
}
return
_results
;
};
...
...
@@ -631,6 +644,9 @@
return
delete
this
.
nested
;
}
}
},
update
:
function
(
models
)
{
return
this
.
nested
.
update
(
models
);
}
},
unless
:
{
...
...
@@ -643,6 +659,9 @@
},
routine
:
function
(
el
,
value
)
{
return
Rivets
.
binders
[
"if"
].
routine
.
call
(
this
,
el
,
!
value
);
},
update
:
function
(
models
)
{
return
Rivets
.
binders
[
"if"
].
update
.
call
(
this
,
models
);
}
},
"on-*"
:
{
...
...
@@ -737,6 +756,24 @@
}
}
return
_results
;
},
update
:
function
(
models
)
{
var
data
,
key
,
model
,
view
,
_i
,
_len
,
_ref
,
_results
;
data
=
{};
for
(
key
in
models
)
{
model
=
models
[
key
];
if
(
key
!==
this
.
args
[
0
])
{
data
[
key
]
=
model
;
}
}
_ref
=
this
.
iterated
;
_results
=
[];
for
(
_i
=
0
,
_len
=
_ref
.
length
;
_i
<
_len
;
_i
++
)
{
view
=
_ref
[
_i
];
_results
.
push
(
view
.
update
(
data
));
}
return
_results
;
}
},
"class-*"
:
function
(
el
,
value
)
{
...
...
dist/rivets.min.js
View file @
54ae655
This diff is collapsed.
Click to expand it.
package.json
View file @
54ae655
{
"name"
:
"rivets"
,
"description"
:
"Declarative data binding facility."
,
"version"
:
"0.5.
7
"
,
"version"
:
"0.5.
8
"
,
"author"
:
"Michael Richards"
,
"url"
:
"http://rivetsjs.com"
,
"main"
:
"./dist/rivets.js"
,
...
...
src/rivets.coffee
View file @
54ae655
# Rivets.js
# =========
# > version: 0.5.
7
# > version: 0.5.
8
# > author: Michael Richards
# > license: MIT
# >
...
...
@@ -137,10 +137,23 @@ class Rivets.Binding
# 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
=
if
@
key
then
@
view
.
models
[
@
key
]
else
@
view
.
models
@
bind
()
update
:
(
models
=
{})
=>
if
@
key
if
models
[
@
key
]
unless
@
options
.
bypass
@
view
.
config
.
adapter
.
unsubscribe
@
model
,
@
keypath
,
@
sync
@
model
=
models
[
@
key
]
if
@
options
.
bypass
@
sync
()
else
@
view
.
config
.
adapter
.
subscribe
@
model
,
@
keypath
,
@
sync
@
sync
()
if
@
view
.
config
.
preloadData
else
@
sync
()
@
binder
.
update
?
.
call
@
,
models
# Rivets.View
# -----------
...
...
@@ -263,9 +276,8 @@ class Rivets.View
# 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
@
models
[
key
]
=
model
for
key
,
model
of
models
binding
.
update
models
for
binding
in
@
bindings
# Rivets.TextTemplateParser
# -------------------------
...
...
@@ -461,6 +473,9 @@ Rivets.binders =
@
nested
.
unbind
()
delete
@
nested
update
:
(
models
)
->
@
nested
.
update
models
unless
:
block
:
true
...
...
@@ -473,6 +488,9 @@ Rivets.binders =
routine
:
(
el
,
value
)
->
Rivets
.
binders
.
if
.
routine
.
call
@
,
el
,
not
value
update
:
(
models
)
->
Rivets
.
binders
.
if
.
update
.
call
@
,
models
"on-*"
:
function
:
true
...
...
@@ -539,6 +557,14 @@ Rivets.binders =
else
if
@
iterated
[
index
].
models
[
modelName
]
isnt
model
@
iterated
[
index
].
update
data
update
:
(
models
)
->
data
=
{}
for
key
,
model
of
models
data
[
key
]
=
model
unless
key
is
@
args
[
0
]
view
.
update
data
for
view
in
@
iterated
"class-*"
:
(
el
,
value
)
->
elClass
=
"
#{
el
.
className
}
"
...
...
Please
register
or
sign in
to post a comment