Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
T
todomvc
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
Analytics
Analytics
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
Sven Franck
todomvc
Commits
f7e1b55e
Commit
f7e1b55e
authored
May 01, 2013
by
Stephen Sawchuk
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Array.filter && !empty todos && `addItem` simplification.
parent
e6f14976
Changes
2
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
15 additions
and
28 deletions
+15
-28
vanilla-examples/vanillajs/js/controller.js
vanilla-examples/vanillajs/js/controller.js
+8
-10
vanilla-examples/vanillajs/js/store.js
vanilla-examples/vanillajs/js/store.js
+7
-18
No files found.
vanilla-examples/vanillajs/js/controller.js
View file @
f7e1b55e
...
@@ -83,19 +83,16 @@
...
@@ -83,19 +83,16 @@
var
title
=
title
||
''
;
var
title
=
title
||
''
;
if
(
e
.
keyCode
===
this
.
ENTER_KEY
)
{
if
(
e
.
keyCode
===
this
.
ENTER_KEY
)
{
this
.
model
.
create
(
e
.
target
.
value
,
function
(
data
)
{
if
(
e
.
target
.
value
.
trim
()
===
''
)
{
// We want to make sure we don't add incomplete
return
;
// items to the completed tab when you go to
// add an item and you're viewing the completed
// items
if
(
this
.
_getCurrentPage
()
!==
'
completed
'
)
{
this
.
$todoList
.
innerHTML
=
this
.
$todoList
.
innerHTML
+
this
.
view
.
show
(
data
);
}
}
this
.
model
.
create
(
e
.
target
.
value
,
function
(
data
)
{
input
.
value
=
''
;
input
.
value
=
''
;
this
.
_filter
(
true
);
}.
bind
(
this
));
}.
bind
(
this
));
}
}
this
.
_filter
();
};
};
/**
/**
...
@@ -290,8 +287,9 @@
...
@@ -290,8 +287,9 @@
/**
/**
* Re-filters the todo items, based on the active route.
* Re-filters the todo items, based on the active route.
* @param {boolean|undefined} force forces a re-painting of todo items.
*/
*/
Controller
.
prototype
.
_filter
=
function
()
{
Controller
.
prototype
.
_filter
=
function
(
force
)
{
var
activeRoute
=
this
.
_activeRoute
.
charAt
(
0
).
toUpperCase
()
+
this
.
_activeRoute
.
substr
(
1
);
var
activeRoute
=
this
.
_activeRoute
.
charAt
(
0
).
toUpperCase
()
+
this
.
_activeRoute
.
substr
(
1
);
// Update the elements on the page, which change with each completed todo
// Update the elements on the page, which change with each completed todo
...
@@ -300,7 +298,7 @@
...
@@ -300,7 +298,7 @@
// If the last active route isn't "All", or we're switching routes, we
// If the last active route isn't "All", or we're switching routes, we
// re-create the todo item elements, calling:
// re-create the todo item elements, calling:
// this.show[All|Active|Completed]();
// this.show[All|Active|Completed]();
if
(
this
.
_lastActiveRoute
!==
'
All
'
||
this
.
_lastActiveRoute
!==
activeRoute
)
{
if
(
force
||
this
.
_lastActiveRoute
!==
'
All
'
||
this
.
_lastActiveRoute
!==
activeRoute
)
{
this
[
'
show
'
+
activeRoute
]();
this
[
'
show
'
+
activeRoute
]();
}
}
...
...
vanilla-examples/vanillajs/js/store.js
View file @
f7e1b55e
...
@@ -43,28 +43,17 @@
...
@@ -43,28 +43,17 @@
* });
* });
*/
*/
Store
.
prototype
.
find
=
function
(
query
,
callback
)
{
Store
.
prototype
.
find
=
function
(
query
,
callback
)
{
var
data
=
JSON
.
parse
(
localStorage
[
this
.
_dbName
]).
todos
;
if
(
!
callback
)
{
var
items
=
[]
;
return
;
var
found
;
}
callback
=
callback
||
function
()
{}
;
var
todos
=
JSON
.
parse
(
localStorage
[
this
.
_dbName
]).
todos
;
for
(
var
i
=
0
;
i
<
data
.
length
;
i
++
)
{
callback
.
call
(
this
,
todos
.
filter
(
function
(
todo
)
{
for
(
var
q
in
query
)
{
for
(
var
q
in
query
)
{
if
(
query
[
q
]
!==
data
[
i
][
q
])
{
return
query
[
q
]
===
todo
[
q
];
found
=
false
;
break
;
}
else
{
found
=
true
;
}
}
}
}));
if
(
found
)
{
items
.
push
(
data
[
i
]);
}
}
callback
.
call
(
this
,
items
);
};
};
/**
/**
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment