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
ac44ecc6
Commit
ac44ecc6
authored
May 29, 2013
by
Stephen Sawchuk
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
restructured canjs_require + code style.
parent
d59b2617
Changes
4
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
70 additions
and
49 deletions
+70
-49
labs/dependency-examples/canjs_require/js/app.js
labs/dependency-examples/canjs_require/js/app.js
+34
-28
labs/dependency-examples/canjs_require/js/controls/todos.js
labs/dependency-examples/canjs_require/js/controls/todos.js
+9
-5
labs/dependency-examples/canjs_require/js/models/localstorage.js
...pendency-examples/canjs_require/js/models/localstorage.js
+16
-10
labs/dependency-examples/canjs_require/js/models/todo.js
labs/dependency-examples/canjs_require/js/models/todo.js
+11
-6
No files found.
labs/dependency-examples/canjs_require/js/app.js
View file @
ac44ecc6
/*global require*/
/*global require
*/
require
.
config
({
require
.
config
({
paths
:
{
paths
:
{
jquery
:
'
../bower_components/jquery/jquery
'
,
jquery
:
'
../bower_components/jquery/jquery
'
,
...
@@ -6,35 +6,41 @@ require.config({
...
@@ -6,35 +6,41 @@ require.config({
}
}
});
});
require
([
'
can/util/library
'
,
'
can/route
'
,
'
app/todos
'
,
'
app/models/todo
'
,
'
can/view/ejs
'
,
'
can/view/mustache
'
],
require
([
function
(
can
,
route
,
Todos
,
Model
)
{
'
can/util/library
'
,
'
use strict
'
;
'
can/route
'
,
'
controls/todos
'
,
'
models/todo
'
,
'
can/view/ejs
'
,
'
can/view/mustache
'
],
function
(
can
,
route
,
Todos
,
Model
)
{
'
use strict
'
;
// Set up a route that maps to the `filter` attribute
// Set up a route that maps to the `filter` attribute
route
(
'
:filter
'
);
route
(
'
:filter
'
);
// Delay routing until we initialized everything
// Delay routing until we initialized everything
route
.
ready
(
false
);
route
.
ready
(
false
);
// View helper for pluralizing strings
// View helper for pluralizing strings
can
.
Mustache
.
registerHelper
(
'
todoPlural
'
,
function
(
str
,
attr
)
{
can
.
Mustache
.
registerHelper
(
'
todoPlural
'
,
function
(
str
,
attr
)
{
return
str
+
(
attr
.
call
(
this
.
todos
)
!==
1
?
'
s
'
:
''
);
return
str
+
(
attr
.
call
(
this
.
todos
)
!==
1
?
'
s
'
:
''
);
});
});
// Find all Todos
// Find all Todos
Model
.
findAll
({},
function
(
todos
)
{
Model
.
findAll
({},
function
(
todos
)
{
// Wire it up. Instantiate a new Todos control
// Wire it up. Instantiate a new Todos control
new
Todos
(
'
#todoapp
'
,
{
new
Todos
(
'
#todoapp
'
,
{
// The (Todo) model that the control should use
// The (Todo) model that the control should use
Model
:
Model
,
Model
:
Model
,
// The list of Todos retrieved from the model
// The list of Todos retrieved from the model
todos
:
todos
,
todos
:
todos
,
// The control state for filtering the view (in our case the router)
// The control state for filtering the view (in our case the router)
state
:
can
.
route
,
state
:
can
.
route
,
// The view to render
// The view to render
view
:
'
views/todos.mustache
'
view
:
'
views/todos.mustache
'
});
});
});
// Now we can start routing
route
.
ready
(
true
);
});
});
// Now we can start routing
route
.
ready
(
true
);
});
labs/dependency-examples/canjs_require/js/
app
/todos.js
→
labs/dependency-examples/canjs_require/js/
controls
/todos.js
View file @
ac44ecc6
/*global define*/
/*global define, window */
define
([
'
can/util/library
'
,
'
can/control
'
],
function
(
can
,
Control
)
{
/*jshint newcap:false */
define
([
'
can/util/library
'
,
'
can/control
'
],
function
(
can
,
Control
)
{
'
use strict
'
;
'
use strict
'
;
var
ENTER_KEY
=
13
;
var
ENTER_KEY
=
13
;
...
@@ -26,8 +30,8 @@ define(['can/util/library', 'can/control'], function (can, Control) {
...
@@ -26,8 +30,8 @@ define(['can/util/library', 'can/control'], function (can, Control) {
text
:
value
,
text
:
value
,
complete
:
false
complete
:
false
}).
save
(
function
()
{
}).
save
(
function
()
{
el
.
val
(
''
);
el
.
val
(
''
);
});
});
}
}
},
},
...
@@ -112,4 +116,4 @@ define(['can/util/library', 'can/control'], function (can, Control) {
...
@@ -112,4 +116,4 @@ define(['can/util/library', 'can/control'], function (can, Control) {
});
});
return
Todos
;
return
Todos
;
});
});
\ No newline at end of file
labs/dependency-examples/canjs_require/js/
app/
models/localstorage.js
→
labs/dependency-examples/canjs_require/js/models/localstorage.js
View file @
ac44ecc6
/*global define*/
/*global define, window */
define
([
'
can/util/library
'
,
'
can/model
'
],
function
(
can
,
Model
)
{
/*jshint newcap:false */
define
([
'
can/util/library
'
,
'
can/model
'
],
function
(
can
,
Model
)
{
'
use strict
'
;
'
use strict
'
;
var
LocalStorage
=
Model
({
var
LocalStorage
=
Model
({
// Implement local storage handling
// Implement local storage handling
localStore
:
function
(
cb
)
{
localStore
:
function
(
cb
)
{
var
name
=
this
.
name
,
var
name
=
this
.
name
;
data
=
JSON
.
parse
(
window
.
localStorage
[
name
]
||
(
window
.
localStorage
[
name
]
=
'
[]
'
)),
var
data
=
JSON
.
parse
(
window
.
localStorage
[
name
]
||
(
window
.
localStorage
[
name
]
=
'
[]
'
));
res
=
cb
.
call
(
this
,
data
);
var
res
=
cb
.
call
(
this
,
data
);
if
(
res
!==
false
)
{
if
(
res
!==
false
)
{
can
.
each
(
data
,
function
(
todo
)
{
can
.
each
(
data
,
function
(
todo
)
{
delete
todo
.
editing
;
delete
todo
.
editing
;
});
});
window
.
localStorage
[
name
]
=
JSON
.
stringify
(
data
);
window
.
localStorage
[
name
]
=
JSON
.
stringify
(
data
);
}
}
},
},
...
@@ -19,8 +25,8 @@ define(['can/util/library', 'can/model'], function (can, Model) {
...
@@ -19,8 +25,8 @@ define(['can/util/library', 'can/model'], function (can, Model) {
findAll
:
function
()
{
findAll
:
function
()
{
var
def
=
new
can
.
Deferred
();
var
def
=
new
can
.
Deferred
();
this
.
localStore
(
function
(
todos
)
{
this
.
localStore
(
function
(
todos
)
{
var
instances
=
[]
,
var
instances
=
[]
;
self
=
this
;
var
self
=
this
;
can
.
each
(
todos
,
function
(
todo
)
{
can
.
each
(
todos
,
function
(
todo
)
{
instances
.
push
(
new
self
(
todo
));
instances
.
push
(
new
self
(
todo
));
});
});
...
@@ -54,7 +60,8 @@ define(['can/util/library', 'can/model'], function (can, Model) {
...
@@ -54,7 +60,8 @@ define(['can/util/library', 'can/model'], function (can, Model) {
},
},
update
:
function
(
id
,
attrs
)
{
update
:
function
(
id
,
attrs
)
{
var
def
=
new
can
.
Deferred
(),
todo
;
var
def
=
new
can
.
Deferred
();
var
todo
;
this
.
localStore
(
function
(
todos
)
{
this
.
localStore
(
function
(
todos
)
{
for
(
var
i
=
0
;
i
<
todos
.
length
;
i
++
)
{
for
(
var
i
=
0
;
i
<
todos
.
length
;
i
++
)
{
if
(
todos
[
i
].
id
===
id
)
{
if
(
todos
[
i
].
id
===
id
)
{
...
@@ -70,5 +77,4 @@ define(['can/util/library', 'can/model'], function (can, Model) {
...
@@ -70,5 +77,4 @@ define(['can/util/library', 'can/model'], function (can, Model) {
},
{});
},
{});
return
LocalStorage
;
return
LocalStorage
;
});
});
\ No newline at end of file
labs/dependency-examples/canjs_require/js/
app/
models/todo.js
→
labs/dependency-examples/canjs_require/js/models/todo.js
View file @
ac44ecc6
/*global define*/
/*global define */
define
([
'
can/util/library
'
,
'
can/observe
'
,
'
app/models/localstorage
'
],
function
(
can
,
Observe
,
LocalStorage
)
{
/*jshint newcap:false */
define
([
'
can/util/library
'
,
'
can/observe
'
,
'
models/localstorage
'
],
function
(
can
,
Observe
,
LocalStorage
)
{
'
use strict
'
;
'
use strict
'
;
// Basic Todo entry model
// Basic Todo entry model
...
@@ -37,10 +42,10 @@ define(['can/util/library', 'can/observe', 'app/models/localstorage'], function
...
@@ -37,10 +42,10 @@ define(['can/util/library', 'can/observe', 'app/models/localstorage'], function
// Returns a new can.Observe.List that contains only the Todos
// Returns a new can.Observe.List that contains only the Todos
// matching the current filter
// matching the current filter
byFilter
:
function
(
filter
)
{
byFilter
:
function
(
filter
)
{
var
filtered
=
new
Observe
.
List
();
var
filtered
=
new
Observe
.
List
();
can
.
each
(
this
,
function
(
todo
)
{
can
.
each
(
this
,
function
(
todo
)
{
if
(
todo
.
matches
(
filter
))
{
if
(
todo
.
matches
(
filter
))
{
filtered
.
push
(
todo
);
filtered
.
push
(
todo
);
}
}
});
});
...
@@ -48,7 +53,7 @@ define(['can/util/library', 'can/observe', 'app/models/localstorage'], function
...
@@ -48,7 +53,7 @@ define(['can/util/library', 'can/observe', 'app/models/localstorage'], function
},
},
// Returns the list to display based on the currently set `filter`
// Returns the list to display based on the currently set `filter`
displayList
:
function
()
{
displayList
:
function
()
{
return
this
.
byFilter
(
this
.
attr
(
'
filter
'
));
return
this
.
byFilter
(
this
.
attr
(
'
filter
'
));
}
}
});
});
...
...
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