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
b4993914
authored
2012-07-09 22:03:40 -0700
by
Michael Richards
Browse Files
Options
Browse Files
Tag
Download
Email Patches
Plain Diff
Replace Array::map call with a list comprehension and remove the polypill.
1 parent
1b2c90bc
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
12 additions
and
49 deletions
lib/rivets.js
src/rivets.coffee
lib/rivets.js
View file @
b499391
...
...
@@ -12,30 +12,6 @@
};
}
if
(
!
Array
.
prototype
.
map
)
{
Array
.
prototype
.
map
=
function
(
callback
)
{
var
A
,
O
,
T
,
k
,
len
;
if
(
this
===
null
)
{
throw
new
TypeError
(
"Can't convert "
+
this
+
" to object"
);
}
O
=
Object
(
this
);
len
=
O
.
length
>>>
0
;
if
(
typeof
callback
!==
'function'
)
{
throw
new
TypeError
(
""
+
callback
+
" is not a function"
);
}
T
=
arguments
[
1
];
A
=
new
Array
(
len
);
k
=
0
;
while
(
k
<
len
)
{
if
(
k
in
O
)
{
A
[
k
]
=
callbackfn
.
call
(
T
,
O
[
k
],
k
,
O
);
}
k
++
;
}
return
A
;
};
}
Rivets
.
Binding
=
(
function
()
{
function
Binding
(
el
,
type
,
model
,
keypath
,
formatters
)
{
...
...
@@ -113,7 +89,7 @@
};
View
.
prototype
.
build
=
function
()
{
var
attribute
,
bindingRegExp
,
keypath
,
model
,
node
,
path
,
pipes
,
type
,
_i
,
_len
,
_ref
,
_results
;
var
attribute
,
bindingRegExp
,
keypath
,
model
,
node
,
path
,
pipe
,
pipe
s
,
type
,
_i
,
_len
,
_ref
,
_results
;
this
.
bindings
=
[];
bindingRegExp
=
this
.
bindingRegExp
();
_ref
=
this
.
el
.
getElementsByTagName
(
'*'
);
...
...
@@ -128,9 +104,16 @@
attribute
=
_ref1
[
_j
];
if
(
bindingRegExp
.
test
(
attribute
.
name
))
{
type
=
attribute
.
name
.
replace
(
bindingRegExp
,
''
);
pipes
=
attribute
.
value
.
split
(
'|'
).
map
(
function
(
pipe
)
{
return
pipe
.
trim
();
});
pipes
=
(
function
()
{
var
_k
,
_len2
,
_ref2
,
_results2
;
_ref2
=
attribute
.
value
.
split
(
'|'
);
_results2
=
[];
for
(
_k
=
0
,
_len2
=
_ref2
.
length
;
_k
<
_len2
;
_k
++
)
{
pipe
=
_ref2
[
_k
];
_results2
.
push
(
pipe
.
trim
());
}
return
_results2
;
})();
path
=
pipes
.
shift
().
split
(
'.'
);
model
=
this
.
models
[
path
.
shift
()];
keypath
=
path
.
join
(
'.'
);
...
...
src/rivets.coffee
View file @
b499391
...
...
@@ -9,26 +9,6 @@ Rivets = {}
# Polyfill For String::trim.
unless
String
::
trim
then
String
::
trim
=
->
@
replace
/^\s+|\s+$/g
,
""
# Polyfill For Array::map
unless
Array
::
map
Array
::
map
=
(
callback
)
->
if
this
is
null
throw
new
TypeError
"Can't convert
#{
this
}
to object"
O
=
Object
(
this
)
len
=
O
.
length
>>>
0
throw
new
TypeError
"
#{
callback
}
is not a function"
unless
typeof
callback
is
'function'
T
=
arguments
[
1
]
A
=
new
Array
(
len
)
k
=
0
;
while
k
<
len
A
[
k
]
=
callbackfn
.
call
(
T
,
O
[
k
],
k
,
O
)
if
k
of
O
k
++
return
A
# A single binding between a model attribute and a DOM element.
class
Rivets
.
Binding
# All information about the binding is passed into the constructor; the DOM
...
...
@@ -88,7 +68,7 @@ class Rivets.View
for
attribute
in
node
.
attributes
if
bindingRegExp
.
test
attribute
.
name
type
=
attribute
.
name
.
replace
bindingRegExp
,
''
pipes
=
attribute
.
value
.
split
(
'|'
).
map
(
pipe
)
->
pipe
.
trim
(
)
pipes
=
(
pipe
.
trim
()
for
pipe
in
attribute
.
value
.
split
'|'
)
path
=
pipes
.
shift
().
split
'.'
model
=
@
models
[
path
.
shift
()]
keypath
=
path
.
join
'.'
...
...
Please
register
or
sign in
to post a comment