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
Eugene Shen
todomvc
Commits
c4c8e3ee
Commit
c4c8e3ee
authored
Jan 19, 2012
by
ben hockey
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
use the length of a filtered array rather than keep a running count
parent
d502e4eb
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
20 additions
and
24 deletions
+20
-24
todo-example/dojo/js/todo/model/TodoModel.js
todo-example/dojo/js/todo/model/TodoModel.js
+20
-24
No files found.
todo-example/dojo/js/todo/model/TodoModel.js
View file @
c4c8e3ee
...
@@ -2,19 +2,19 @@ define(["dojo/_base/declare", "dojox/mvc/StatefulModel", "todo/store/LocalStorag
...
@@ -2,19 +2,19 @@ define(["dojo/_base/declare", "dojox/mvc/StatefulModel", "todo/store/LocalStorag
function
(
declare
,
StatefulModel
,
LocalStorage
,
mvc
,
lang
,
array
)
{
function
(
declare
,
StatefulModel
,
LocalStorage
,
mvc
,
lang
,
array
)
{
return
declare
([
StatefulModel
],
{
return
declare
([
StatefulModel
],
{
/**
/**
* Default model structure, overriden by any
* Default model structure, overriden by any
* items found in localStorage.
* items found in localStorage.
*/
*/
data
:
{
data
:
{
id
:
"
local_storage_todos
"
,
id
:
"
local_storage_todos
"
,
todos
:
[],
todos
:
[],
incomplete
:
0
,
incomplete
:
0
,
complete
:
0
complete
:
0
},
},
/**
/**
* Initialise our custom dojo store, backed by localStorage. This will be
* Initialise our custom dojo store, backed by localStorage. This will be
* used to read the initial items, if available, and persist the current items
* used to read the initial items, if available, and persist the current items
* when the application finishes.
* when the application finishes.
*/
*/
...
@@ -24,7 +24,7 @@ define(["dojo/_base/declare", "dojox/mvc/StatefulModel", "todo/store/LocalStorag
...
@@ -24,7 +24,7 @@ define(["dojo/_base/declare", "dojox/mvc/StatefulModel", "todo/store/LocalStorag
/**
/**
* Attempt to read todo items from localStorage,
* Attempt to read todo items from localStorage,
* returning default value the first time the application
* returning default value the first time the application
* is loaded... The "id" parameter is used as the unique
* is loaded... The "id" parameter is used as the unique
* localStorage key for this object.
* localStorage key for this object.
*/
*/
var
data
=
this
.
store
.
get
(
this
.
data
.
id
)
||
this
.
data
;
var
data
=
this
.
store
.
get
(
this
.
data
.
id
)
||
this
.
data
;
...
@@ -35,18 +35,18 @@ define(["dojo/_base/declare", "dojox/mvc/StatefulModel", "todo/store/LocalStorag
...
@@ -35,18 +35,18 @@ define(["dojo/_base/declare", "dojox/mvc/StatefulModel", "todo/store/LocalStorag
},
},
setUpModelBinding
:
function
()
{
setUpModelBinding
:
function
()
{
/**
/**
* Set up a composite model attribute, "complete", that is automatically
* Set up a composite model attribute, "complete", that is automatically
* calculated whenever the "incomplete" source value is modified. The "complete"
* calculated whenever the "incomplete" source value is modified. The "complete"
* attribute is bound to a view widget, displaying the number of items that can
* attribute is bound to a view widget, displaying the number of items that can
* be cleared using the link.
* be cleared using the link.
*/
*/
mvc
.
bind
(
this
.
incomplete
,
"
value
"
,
this
.
complete
,
"
value
"
,
lang
.
hitch
(
this
,
function
(
value
)
{
mvc
.
bind
(
this
.
incomplete
,
"
value
"
,
this
.
complete
,
"
value
"
,
lang
.
hitch
(
this
,
function
(
value
)
{
return
this
.
todos
.
get
(
"
length
"
)
-
value
;
return
this
.
todos
.
get
(
"
length
"
)
-
value
;
}));
}));
/**
/**
* Bind all pre-populated todo items to update the
* Bind all pre-populated todo items to update the
* total item values when the "isDone" attribute is changed.
* total item values when the "isDone" attribute is changed.
*/
*/
array
.
forEach
(
this
.
todos
,
lang
.
hitch
(
this
,
"
bindIsDone
"
));
array
.
forEach
(
this
.
todos
,
lang
.
hitch
(
this
,
"
bindIsDone
"
));
...
@@ -60,10 +60,10 @@ define(["dojo/_base/declare", "dojox/mvc/StatefulModel", "todo/store/LocalStorag
...
@@ -60,10 +60,10 @@ define(["dojo/_base/declare", "dojox/mvc/StatefulModel", "todo/store/LocalStorag
this
.
todos
.
watch
(
lang
.
hitch
(
this
,
"
onTodosModelChange
"
));
this
.
todos
.
watch
(
lang
.
hitch
(
this
,
"
onTodosModelChange
"
));
},
},
/**
/**
* Set up binding on a todo item, so that when the
* Set up binding on a todo item, so that when the
* item's checked attribute changes, we re-calculate
* item's checked attribute changes, we re-calculate
* the composite model attribute's value, "complete".
* the composite model attribute's value, "complete".
*/
*/
bindIsDone
:
function
(
item
)
{
bindIsDone
:
function
(
item
)
{
mvc
.
bindInputs
([
item
.
isDone
],
lang
.
hitch
(
this
,
"
updateTotalItemsLeft
"
));
mvc
.
bindInputs
([
item
.
isDone
],
lang
.
hitch
(
this
,
"
updateTotalItemsLeft
"
));
...
@@ -71,9 +71,9 @@ define(["dojo/_base/declare", "dojox/mvc/StatefulModel", "todo/store/LocalStorag
...
@@ -71,9 +71,9 @@ define(["dojo/_base/declare", "dojox/mvc/StatefulModel", "todo/store/LocalStorag
/**
/**
* When todos array is modified, we need to update the composite
* When todos array is modified, we need to update the composite
* value attributes. If the modification was an addition, ensure the
* value attributes. If the modification was an addition, ensure the
* "isDone" attribute is being watched for updates.
* "isDone" attribute is being watched for updates.
*/
*/
onTodosModelChange
:
function
(
prop
,
oldValue
,
newValue
)
{
onTodosModelChange
:
function
(
prop
,
oldValue
,
newValue
)
{
this
.
updateTotalItemsLeft
();
this
.
updateTotalItemsLeft
();
...
@@ -88,13 +88,9 @@ define(["dojo/_base/declare", "dojox/mvc/StatefulModel", "todo/store/LocalStorag
...
@@ -88,13 +88,9 @@ define(["dojo/_base/declare", "dojox/mvc/StatefulModel", "todo/store/LocalStorag
* cause the bound "complete" value to be updated as well.
* cause the bound "complete" value to be updated as well.
*/
*/
updateTotalItemsLeft
:
function
()
{
updateTotalItemsLeft
:
function
()
{
var
remaining
=
0
;
this
.
incomplete
.
set
(
"
value
"
,
array
.
filter
(
this
.
todos
,
function
(
item
)
{
return
item
&&
!
item
.
isDone
.
value
;
array
.
forEach
(
this
.
todos
,
function
(
item
)
{
}).
length
);
item
&&
!
item
.
isDone
.
value
&&
remaining
++
;
});
this
.
incomplete
.
set
(
"
value
"
,
remaining
);
}
}
});
});
});
});
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