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
4ecf41db
Commit
4ecf41db
authored
Mar 16, 2013
by
Pascal Hartig
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
CanJS: Replaced localstorage plugin with component
parent
44dc7cd0
Changes
4
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
77 additions
and
4 deletions
+77
-4
architecture-examples/canjs/component.json
architecture-examples/canjs/component.json
+9
-0
architecture-examples/canjs/components/canjs-localstorage/can.localstorage.js
...s/canjs/components/canjs-localstorage/can.localstorage.js
+66
-0
architecture-examples/canjs/index.html
architecture-examples/canjs/index.html
+2
-2
architecture-examples/canjs/js/lib/can.localstorage.min.js
architecture-examples/canjs/js/lib/can.localstorage.min.js
+0
-2
No files found.
architecture-examples/canjs/component.json
0 → 100644
View file @
4ecf41db
{
"name"
:
"todomvc-canjs"
,
"version"
:
"0.0.0"
,
"dependencies"
:
{
"jquery"
:
"~1.9.1"
,
"canjs"
:
"~1.1.4"
,
"canjs-localstorage"
:
"~0.1.0"
}
}
architecture-examples/canjs/components/canjs-localstorage/can.localstorage.js
0 → 100644
View file @
4ecf41db
can
.
Model
(
'
can.Model.LocalStorage
'
,
{
// Implement local storage handling
localStore
:
function
(
cb
)
{
var
name
=
this
.
name
,
data
=
JSON
.
parse
(
window
.
localStorage
[
name
]
||
(
window
.
localStorage
[
name
]
=
'
[]
'
)),
res
=
cb
.
call
(
this
,
data
);
if
(
res
!==
false
)
{
can
.
each
(
data
,
function
(
todo
)
{
delete
todo
.
editing
;
});
window
.
localStorage
[
name
]
=
JSON
.
stringify
(
data
);
}
},
findAll
:
function
(
params
)
{
var
def
=
new
can
.
Deferred
();
this
.
localStore
(
function
(
todos
)
{
var
instances
=
[],
self
=
this
;
can
.
each
(
todos
,
function
(
todo
)
{
instances
.
push
(
new
self
(
todo
));
});
def
.
resolve
({
data
:
instances
});
});
return
def
;
},
destroy
:
function
(
id
)
{
var
def
=
new
can
.
Deferred
();
this
.
localStore
(
function
(
todos
)
{
for
(
var
i
=
0
;
i
<
todos
.
length
;
i
++
)
{
if
(
todos
[
i
].
id
===
id
)
{
todos
.
splice
(
i
,
1
);
break
;
}
}
def
.
resolve
({});
});
return
def
;
},
create
:
function
(
attrs
)
{
var
def
=
new
can
.
Deferred
();
this
.
localStore
(
function
(
todos
)
{
attrs
.
id
=
attrs
.
id
||
parseInt
(
100000
*
Math
.
random
(),
10
);
todos
.
push
(
attrs
);
});
def
.
resolve
({
id
:
attrs
.
id
});
return
def
;
},
update
:
function
(
id
,
attrs
)
{
var
def
=
new
can
.
Deferred
(),
todo
;
this
.
localStore
(
function
(
todos
)
{
for
(
var
i
=
0
;
i
<
todos
.
length
;
i
++
)
{
if
(
todos
[
i
].
id
===
id
)
{
todo
=
todos
[
i
];
break
;
}
}
can
.
extend
(
todo
,
attrs
);
});
def
.
resolve
({});
return
def
;
}
},
{});
\ No newline at end of file
architecture-examples/canjs/index.html
View file @
4ecf41db
...
...
@@ -17,10 +17,10 @@
<script
src=
"components/jquery/jquery.js"
></script>
<script
src=
"components/todomvc-common/base.js"
></script>
<script
src=
"components/canjs/can.jquery.js"
></script>
<script
src=
"components/canjs-localstorage/can.localstorage.js"
></script>
<script
src=
"js/lib/can.mustache.min.js"
></script>
<script
src=
"js/lib/can.localstorage.min.js"
></script>
<script
src=
"js/models/todo.js"
></script>
<script
src=
"js/todos/todos.js"
></script>
<script
src=
"js/app.js"
></script>
...
...
architecture-examples/canjs/js/lib/can.localstorage.min.js
deleted
100644 → 0
View file @
44dc7cd0
can
.
Model
(
"
can.Model.LocalStorage
"
,{
localStore
:
function
(
b
){
var
c
=
this
.
storageName
,
a
=
JSON
.
parse
(
window
.
localStorage
[
c
]
||
(
window
.
localStorage
[
c
]
=
"
[]
"
));
!
1
!==
b
.
call
(
this
,
a
)
&&
(
can
.
each
(
a
,
function
(
a
){
delete
a
.
editing
}),
window
.
localStorage
[
c
]
=
JSON
.
stringify
(
a
))},
findAll
:
function
(){
var
b
=
new
can
.
Deferred
;
this
.
localStore
(
function
(
c
){
var
a
=
[],
d
=
this
;
can
.
each
(
c
,
function
(
b
){
a
.
push
(
new
d
(
b
))});
b
.
resolve
({
data
:
a
})});
return
b
},
destroy
:
function
(
b
){
var
c
=
new
can
.
Deferred
;
this
.
localStore
(
function
(
a
){
for
(
var
d
=
0
;
d
<
a
.
length
;
d
++
)
if
(
a
[
d
].
id
===
b
){
a
.
splice
(
d
,
1
);
break
}
c
.
resolve
({})});
return
c
},
create
:
function
(
b
){
var
c
=
new
can
.
Deferred
;
this
.
localStore
(
function
(
a
){
b
.
id
=
b
.
id
||
parseInt
(
1
E5
*
Math
.
random
(),
10
);
a
.
push
(
b
)});
c
.
resolve
({
id
:
b
.
id
});
return
c
},
update
:
function
(
b
,
c
){
var
a
=
new
can
.
Deferred
,
d
;
this
.
localStore
(
function
(
a
){
for
(
var
e
=
0
;
e
<
a
.
length
;
e
++
)
if
(
a
[
e
].
id
===
b
){
d
=
a
[
e
];
break
}
can
.
extend
(
d
,
c
)});
a
.
resolve
({});
return
a
}},{});
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