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
9295d162
Commit
9295d162
authored
Aug 26, 2013
by
Stephen Sawchuk
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
(durandel) code style.
parent
306c0215
Changes
7
Hide whitespace changes
Inline
Side-by-side
Showing
7 changed files
with
54 additions
and
44 deletions
+54
-44
labs/dependency-examples/durandal/js/main.js
labs/dependency-examples/durandal/js/main.js
+15
-11
labs/dependency-examples/durandal/js/viewmodels/entry.js
labs/dependency-examples/durandal/js/viewmodels/entry.js
+2
-1
labs/dependency-examples/durandal/js/viewmodels/list.js
labs/dependency-examples/durandal/js/viewmodels/list.js
+23
-20
labs/dependency-examples/durandal/js/viewmodels/shell.js
labs/dependency-examples/durandal/js/viewmodels/shell.js
+6
-4
labs/dependency-examples/durandal/js/views/list.html
labs/dependency-examples/durandal/js/views/list.html
+1
-1
labs/dependency-examples/durandal/js/views/todoapp.html
labs/dependency-examples/durandal/js/views/todoapp.html
+6
-6
labs/dependency-examples/durandal/readme.md
labs/dependency-examples/durandal/readme.md
+1
-1
No files found.
labs/dependency-examples/durandal/js/main.js
View file @
9295d162
...
...
@@ -69,19 +69,21 @@
});
},
update
:
function
(
element
,
valueAccessor
)
{
ko
.
utils
.
unwrapObservable
(
valueAccessor
());
// for dependency
// ensure that element is visible before trying to focus
setTimeout
(
function
()
{
ko
.
bindingHandlers
.
hasfocus
.
update
(
element
,
valueAccessor
);
},
0
);
}
ko
.
utils
.
unwrapObservable
(
valueAccessor
());
// for dependency
// ensure that element is visible before trying to focus
setTimeout
(
function
()
{
ko
.
bindingHandlers
.
hasfocus
.
update
(
element
,
valueAccessor
);
},
0
);
}
};
define
([
'
bower_components/durandal/app
'
,
define
([
'
bower_components/durandal/app
'
,
'
bower_components/durandal/viewLocator
'
,
'
bower_components/durandal/system
'
,
'
bower_components/durandal/plugins/router
'
],
function
(
app
,
viewLocator
,
system
,
router
)
{
'
bower_components/durandal/plugins/router
'
],
function
(
app
,
viewLocator
,
system
,
router
)
{
//>>excludeStart("build", true);
system
.
debug
(
true
);
...
...
@@ -89,6 +91,7 @@
// this ensures that the title is simply the caption provided on the route
app
.
title
=
undefined
;
app
.
start
().
then
(
function
()
{
// Replace 'viewmodels' in the moduleId with 'views' to locate the view.
// Look for partial views in a 'views' folder in the root.
...
...
@@ -96,13 +99,14 @@
// configure routing
router
.
useConvention
(
'
js/viewmodels
'
);
router
.
mapNav
({
url
:
'
/
'
,
moduleId
:
'
js/viewmodels/todoapp
'
,
name
:
'
TodoMVC
'
,
caption
:
'
Durandal • TodoMVC
'
});
router
.
mapNav
({
url
:
'
#/:filter
'
,
moduleId
:
'
js/viewmodels/todoapp
'
,
...
...
@@ -117,4 +121,4 @@
app
.
setRoot
(
'
js/viewmodels/shell
'
);
});
});
}());
\ No newline at end of file
})();
\ No newline at end of file
labs/dependency-examples/durandal/js/viewmodels/entry.js
View file @
9295d162
...
...
@@ -2,17 +2,18 @@
define
([
'
bower_components/durandal/app
'
],
function
(
app
)
{
'
use strict
'
;
var
ViewModel
=
function
()
{
var
self
=
this
;
// store the new todo value being entered
self
.
current
=
ko
.
observable
();
// add a new todo, when enter key is pressed
self
.
add
=
function
()
{
var
current
=
self
.
current
().
trim
();
if
(
current
)
{
app
.
trigger
(
'
todoitem
'
,
current
);
self
.
current
(
''
);
...
...
labs/dependency-examples/durandal/js/viewmodels/list.js
View file @
9295d162
...
...
@@ -3,7 +3,6 @@ define([
'
bower_components/durandal/app
'
,
'
js/viewmodels/shell
'
],
function
(
app
,
shell
)
{
'
use strict
'
;
// represent a single todo item
...
...
@@ -34,13 +33,16 @@ define([
self
.
todos
(
todosFromlocalStorage
);
// internal computed observable that fires whenever anything changes in our todos
// internal computed observable that fires whenever anything changes in
// our todos
ko
.
computed
(
function
()
{
// store a clean copy to local storage, which also creates a dependency on the observableArray and all observables in each item
// store a clean copy to local storage, which also creates a dependency
// on the observableArray and all observables in each item
localStorage
.
setItem
(
'
todos-durandal
'
,
ko
.
toJSON
(
self
.
todos
()));
}).
extend
({
// save at most twice per second
throttle
:
500
});
// save at most twice per second
});
};
...
...
@@ -55,16 +57,16 @@ define([
self
.
filteredTodos
=
ko
.
computed
(
function
()
{
switch
(
self
.
showMode
())
{
case
'
active
'
:
return
self
.
todos
().
filter
(
function
(
todo
)
{
return
!
todo
.
completed
();
});
case
'
completed
'
:
return
self
.
todos
().
filter
(
function
(
todo
)
{
return
todo
.
completed
();
});
default
:
return
self
.
todos
();
case
'
active
'
:
return
self
.
todos
().
filter
(
function
(
todo
)
{
return
!
todo
.
completed
();
});
case
'
completed
'
:
return
self
.
todos
().
filter
(
function
(
todo
)
{
return
todo
.
completed
();
});
default
:
return
self
.
todos
();
}
});
...
...
@@ -75,7 +77,8 @@ define([
self
.
todos
.
remove
(
todo
);
};
self
.
editTitle
=
ko
.
observable
(
''
);
// shadow variable so that the edit can be discarded on escape
// shadow variable so that the edit can be discarded on escape
self
.
editTitle
=
ko
.
observable
(
''
);
self
.
cancelEdit
=
false
;
// remove all completed todos
...
...
@@ -106,7 +109,7 @@ define([
if
(
!
self
.
cancelEdit
)
{
self
.
itemBeingEdited
(
undefined
);
//trim and save back
//
trim and save back
var
trimmed
=
self
.
editTitle
().
trim
();
item
.
title
(
trimmed
);
...
...
@@ -130,14 +133,16 @@ define([
// writeable computed observable to handle marking all complete/incomplete
self
.
allCompleted
=
ko
.
computed
({
//always return true/false based on the done flag of all todos
//
always return true/false based on the done flag of all todos
read
:
function
()
{
return
!
self
.
remainingCount
();
},
// set all todos to the written value (true/false)
write
:
function
(
newValue
)
{
ko
.
utils
.
arrayForEach
(
self
.
todos
(),
function
(
todo
)
{
// set even if value is the same, as subscribers are not notified in that case
// set even if value is the same, as subscribers are not notified in
// that case
todo
.
completed
(
newValue
);
});
}
...
...
@@ -147,9 +152,7 @@ define([
self
.
getLabel
=
function
(
count
)
{
return
ko
.
utils
.
unwrapObservable
(
count
)
===
1
?
'
item
'
:
'
items
'
;
};
};
return
ViewModel
;
});
labs/dependency-examples/durandal/js/viewmodels/shell.js
View file @
9295d162
/*global define*/
/*global define
*/
define
([
'
bower_components/durandal/plugins/router
'
,
],
function
(
router
)
{
'
use strict
'
;
return
{
router
:
router
,
filter
:
undefined
,
// this is used as the global cache to figure out the filter in effect.
// this is used as the global cache to figure out the filter in effect.
filter
:
undefined
,
activate
:
function
()
{
return
router
.
activate
(
'
todoapp
'
);
}
...
...
labs/dependency-examples/durandal/js/views/list.html
View file @
9295d162
...
...
@@ -17,7 +17,7 @@
<footer
id=
"footer"
data-bind=
"visible: completedCount() || remainingCount()"
>
<span
id=
"todo-count"
>
<strong
data-bind=
"text: remainingCount"
>
0
</strong>
<span
data-bind=
"text: getLabel(
remainingCount
)"
></span>
left
<span
data-bind=
"text: getLabel(
remainingCount
)"
></span>
left
</span>
<ul
id=
"filters"
>
<li>
...
...
labs/dependency-examples/durandal/js/views/todoapp.html
View file @
9295d162
<section
id=
"todoapp"
>
<!--ko compose: {
model: 'js/viewmodels/entry', activate: true
}--><!--/ko-->
<div>
<!--ko compose: {
model: 'js/viewmodels/
entry
', activate: true
model: 'js/viewmodels/
list
', activate: true
}--><!--/ko-->
<div>
<!--ko compose: {
model: 'js/viewmodels/list', activate: true
}--><!--/ko-->
</div>
</div>
</section>
labs/dependency-examples/durandal/readme.md
View file @
9295d162
...
...
@@ -31,4 +31,4 @@ _If you have other helpful links to share, or find any of the links above no lon
## Credit
This
Durandal
TodoMVC application was created by
[
Abhinav Gujjar
](
https://github.com/abhinavgujjar
)
.
This TodoMVC application was created by
[
Abhinav Gujjar
](
https://github.com/abhinavgujjar
)
.
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