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
cbbdbae6
Commit
cbbdbae6
authored
Mar 15, 2015
by
Mathieu Lorber
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
New formatter on all vanilladart code
parent
fe473ce1
Changes
4
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
236 additions
and
240 deletions
+236
-240
examples/vanilladart/lib/models.dart
examples/vanilladart/lib/models.dart
+3
-7
examples/vanilladart/web/dart/TodoApp.dart
examples/vanilladart/web/dart/TodoApp.dart
+149
-148
examples/vanilladart/web/dart/TodoWidget.dart
examples/vanilladart/web/dart/TodoWidget.dart
+82
-83
examples/vanilladart/web/dart/app.dart
examples/vanilladart/web/dart/app.dart
+2
-2
No files found.
examples/vanilladart/lib/models.dart
View file @
cbbdbae6
...
...
@@ -5,7 +5,7 @@ class Todo {
String
title
;
bool
completed
;
Todo
(
this
.
id
,
this
.
title
,
{
this
.
completed
:
false
});
Todo
(
this
.
id
,
this
.
title
,
{
this
.
completed
:
false
});
Todo
.
fromJson
(
Map
json
)
{
id
=
json
[
'id'
];
...
...
@@ -15,10 +15,6 @@ class Todo {
// this is automatically called by JSON.encode
Map
toJson
()
{
return
{
'id'
:
id
,
'title'
:
title
,
'completed'
:
completed
};
return
{
'id'
:
id
,
'title'
:
title
,
'completed'
:
completed
};
}
}
\ No newline at end of file
}
examples/vanilladart/web/dart/TodoApp.dart
View file @
cbbdbae6
part of
todomvc
;
class
TodoApp
{
List
<
TodoWidget
>
todoWidgets
=
new
List
<
TodoWidget
>();
Element
todoListElement
=
querySelector
(
'#todo-list
'
);
Element
mainElement
=
querySelector
(
'#main
'
);
InputElement
checkAllCheckboxElement
=
querySelector
(
'#toggle-all
'
);
Element
footerElement
=
querySelector
(
'#footer
'
);
Element
countElement
=
querySelector
(
'#todo-count
'
);
Element
clearCompletedElement
=
querySelector
(
'#clear-completed
'
);
Element
showAllElement
=
querySelector
(
'#filters a[href="#/
"]'
);
Element
showActiveElement
=
querySelector
(
'#filters a[href="#/active"]'
);
Element
showCompletedElement
=
querySelector
(
'#filters a[href="#/completed"]'
);
TodoApp
()
{
initLocalStorage
();
initElementEventListeners
();
window
.
onHashChange
.
listen
((
e
)
=>
updateFilter
());
updateFooterDisplay
();
}
void
initLocalStorage
()
{
var
jsonList
=
window
.
localStorage
[
'todos-vanilladart'
];
if
(
jsonList
!=
null
)
{
try
{
List
<
Map
>
todos
=
JSON
.
decode
(
jsonList
);
todos
.
forEach
((
todo
)
=>
addTodo
(
new
Todo
.
fromJson
(
todo
)));
}
catch
(
e
)
{
print
(
'Could not load todos form local storage.'
);
}
}
}
void
initElementEventListeners
()
{
InputElement
newTodoElement
=
querySelector
(
'#new-todo'
);
newTodoElement
.
onKeyDown
.
listen
((
KeyboardEvent
e
)
{
if
(
e
.
keyCode
==
KeyCode
.
ENTER
)
{
List
<
TodoWidget
>
todoWidgets
=
new
List
<
TodoWidget
>();
Element
todoListElement
=
querySelector
(
'#todo-list'
);
Element
mainElement
=
querySelector
(
'#main
'
);
InputElement
checkAllCheckboxElement
=
querySelector
(
'#toggle-all
'
);
Element
footerElement
=
querySelector
(
'#footer
'
);
Element
countElement
=
querySelector
(
'#todo-count
'
);
Element
clearCompletedElement
=
querySelector
(
'#clear-completed
'
);
Element
showAllElement
=
querySelector
(
'#filters a[href="#/"]
'
);
Element
showActiveElement
=
querySelector
(
'#filters a[href="#/active
"]'
);
Element
showCompletedElement
=
querySelector
(
'#filters a[href="#/completed"]'
);
TodoApp
()
{
initLocalStorage
();
initElementEventListeners
();
window
.
onHashChange
.
listen
((
e
)
=>
updateFilter
());
updateFooterDisplay
();
}
void
initLocalStorage
()
{
var
jsonList
=
window
.
localStorage
[
'todos-vanilladart'
];
if
(
jsonList
!=
null
)
{
try
{
List
<
Map
>
todos
=
JSON
.
decode
(
jsonList
);
todos
.
forEach
((
todo
)
=>
addTodo
(
new
Todo
.
fromJson
(
todo
)));
}
catch
(
e
)
{
print
(
'Could not load todos form local storage.'
);
}
}
}
void
initElementEventListeners
()
{
InputElement
newTodoElement
=
querySelector
(
'#new-todo'
);
newTodoElement
.
onKeyDown
.
listen
((
KeyboardEvent
e
)
{
if
(
e
.
keyCode
==
KeyCode
.
ENTER
)
{
var
title
=
newTodoElement
.
value
.
trim
();
if
(
title
.
isNotEmpty
)
{
addTodo
(
new
Todo
(
uuid
(),
title
));
...
...
@@ -47,113 +47,114 @@ class TodoApp {
updateFooterDisplay
();
save
();
}
}
});
checkAllCheckboxElement
.
onClick
.
listen
((
e
)
{
for
(
var
todoWidget
in
todoWidgets
)
{
if
(
todoWidget
.
todo
.
completed
!=
checkAllCheckboxElement
.
checked
)
{
todoWidget
.
toggle
();
}
}
updateCounts
();
save
();
});
clearCompletedElement
.
onClick
.
listen
((
_
)
{
var
newList
=
new
List
<
TodoWidget
>();
for
(
TodoWidget
todoWidget
in
todoWidgets
)
{
if
(
todoWidget
.
todo
.
completed
)
{
todoWidget
.
element
.
remove
();
}
else
{
newList
.
add
(
todoWidget
);
}
}
todoWidgets
=
newList
;
updateFooterDisplay
();
save
();
});
}
void
addTodo
(
Todo
todo
)
{
var
todoWidget
=
new
TodoWidget
(
this
,
todo
);
todoWidgets
.
add
(
todoWidget
);
todoListElement
.
nodes
.
add
(
todoWidget
.
createElement
());
}
void
updateFooterDisplay
()
{
var
display
=
todoWidgets
.
length
==
0
?
'none'
:
'block'
;
checkAllCheckboxElement
.
style
.
display
=
display
;
mainElement
.
style
.
display
=
display
;
footerElement
.
style
.
display
=
display
;
updateCounts
();
}
void
updateCounts
()
{
var
complete
=
todoWidgets
.
where
((
w
)
=>
w
.
todo
.
completed
).
length
;
checkAllCheckboxElement
.
checked
=
(
complete
==
todoWidgets
.
length
);
var
left
=
todoWidgets
.
length
-
complete
;
countElement
.
innerHtml
=
'<strong>
$left
</strong> item
${left != 1 ? 's' : ''}
left'
;
if
(
complete
==
0
)
{
clearCompletedElement
.
style
.
display
=
'none'
;
}
else
{
clearCompletedElement
.
style
.
display
=
'block'
;
clearCompletedElement
.
text
=
'Clear completed (
$complete
)'
;
}
updateFilter
();
}
void
removeTodo
(
TodoWidget
todoWidget
)
{
todoWidgets
.
removeAt
(
todoWidgets
.
indexOf
(
todoWidget
));
}
void
updateFilter
()
{
switch
(
window
.
location
.
hash
)
{
case
'#/active'
:
showActive
();
break
;
case
'#/completed'
:
showCompleted
();
break
;
default
:
showAll
();
return
;
}
}
void
showAll
()
{
setSelectedFilter
(
showAllElement
);
for
(
var
todoWidget
in
todoWidgets
)
{
todoWidget
.
visible
=
true
;
}
}
void
showActive
()
{
setSelectedFilter
(
showActiveElement
);
for
(
var
todoWidget
in
todoWidgets
)
{
todoWidget
.
visible
=
!
todoWidget
.
todo
.
completed
;
}
}
void
showCompleted
()
{
setSelectedFilter
(
showCompletedElement
);
for
(
var
todoWidget
in
todoWidgets
)
{
todoWidget
.
visible
=
todoWidget
.
todo
.
completed
;
}
}
void
setSelectedFilter
(
Element
e
)
{
showAllElement
.
classes
.
remove
(
'selected'
);
showActiveElement
.
classes
.
remove
(
'selected'
);
showCompletedElement
.
classes
.
remove
(
'selected'
);
e
.
classes
.
add
(
'selected'
);
}
void
save
()
{
var
todos
=
new
List
<
Todo
>();
for
(
var
todoWidget
in
todoWidgets
)
{
todos
.
add
(
todoWidget
.
todo
);
}
window
.
localStorage
[
'todos-vanilladart'
]
=
JSON
.
encode
(
todos
);
}
}
});
checkAllCheckboxElement
.
onClick
.
listen
((
e
)
{
for
(
var
todoWidget
in
todoWidgets
)
{
if
(
todoWidget
.
todo
.
completed
!=
checkAllCheckboxElement
.
checked
)
{
todoWidget
.
toggle
();
}
}
updateCounts
();
save
();
});
clearCompletedElement
.
onClick
.
listen
((
_
)
{
var
newList
=
new
List
<
TodoWidget
>();
for
(
TodoWidget
todoWidget
in
todoWidgets
)
{
if
(
todoWidget
.
todo
.
completed
)
{
todoWidget
.
element
.
remove
();
}
else
{
newList
.
add
(
todoWidget
);
}
}
todoWidgets
=
newList
;
updateFooterDisplay
();
save
();
});
}
void
addTodo
(
Todo
todo
)
{
var
todoWidget
=
new
TodoWidget
(
this
,
todo
);
todoWidgets
.
add
(
todoWidget
);
todoListElement
.
nodes
.
add
(
todoWidget
.
createElement
());
}
void
updateFooterDisplay
()
{
var
display
=
todoWidgets
.
length
==
0
?
'none'
:
'block'
;
checkAllCheckboxElement
.
style
.
display
=
display
;
mainElement
.
style
.
display
=
display
;
footerElement
.
style
.
display
=
display
;
updateCounts
();
}
void
updateCounts
()
{
var
complete
=
todoWidgets
.
where
((
w
)
=>
w
.
todo
.
completed
).
length
;
checkAllCheckboxElement
.
checked
=
(
complete
==
todoWidgets
.
length
);
var
left
=
todoWidgets
.
length
-
complete
;
countElement
.
innerHtml
=
'<strong>
$left
</strong> item
${left != 1 ? 's' : ''}
left'
;
if
(
complete
==
0
)
{
clearCompletedElement
.
style
.
display
=
'none'
;
}
else
{
clearCompletedElement
.
style
.
display
=
'block'
;
clearCompletedElement
.
text
=
'Clear completed (
$complete
)'
;
}
updateFilter
();
}
void
removeTodo
(
TodoWidget
todoWidget
)
{
todoWidgets
.
removeAt
(
todoWidgets
.
indexOf
(
todoWidget
));
}
void
updateFilter
()
{
switch
(
window
.
location
.
hash
)
{
case
'#/active'
:
showActive
();
break
;
case
'#/completed'
:
showCompleted
();
break
;
default
:
showAll
();
return
;
}
}
void
showAll
()
{
setSelectedFilter
(
showAllElement
);
for
(
var
todoWidget
in
todoWidgets
)
{
todoWidget
.
visible
=
true
;
}
}
void
showActive
()
{
setSelectedFilter
(
showActiveElement
);
for
(
var
todoWidget
in
todoWidgets
)
{
todoWidget
.
visible
=
!
todoWidget
.
todo
.
completed
;
}
}
void
showCompleted
()
{
setSelectedFilter
(
showCompletedElement
);
for
(
var
todoWidget
in
todoWidgets
)
{
todoWidget
.
visible
=
todoWidget
.
todo
.
completed
;
}
}
void
setSelectedFilter
(
Element
e
)
{
showAllElement
.
classes
.
remove
(
'selected'
);
showActiveElement
.
classes
.
remove
(
'selected'
);
showCompletedElement
.
classes
.
remove
(
'selected'
);
e
.
classes
.
add
(
'selected'
);
}
void
save
()
{
var
todos
=
new
List
<
Todo
>();
for
(
var
todoWidget
in
todoWidgets
)
{
todos
.
add
(
todoWidget
.
todo
);
}
window
.
localStorage
[
'todos-vanilladart'
]
=
JSON
.
encode
(
todos
);
}
}
examples/vanilladart/web/dart/TodoWidget.dart
View file @
cbbdbae6
part of
todomvc
;
class
TodoWidget
{
static
const
HtmlEscape
htmlEscape
=
const
HtmlEscape
();
static
const
HtmlEscape
htmlEscape
=
const
HtmlEscape
();
TodoApp
todoApp
;
Todo
todo
;
Element
element
;
InputElement
toggleElement
;
TodoApp
todoApp
;
Todo
todo
;
Element
element
;
InputElement
toggleElement
;
TodoWidget
(
this
.
todoApp
,
this
.
todo
);
TodoWidget
(
this
.
todoApp
,
this
.
todo
);
Element
createElement
()
{
element
=
new
Element
.
html
(
'''
Element
createElement
()
{
element
=
new
Element
.
html
(
'''
<li
${todo.completed ? 'class="completed"' : ''}
>
<div class='
view
'>
<input class='
toggle
' type='
checkbox
'
${todo.completed ? 'checked' : ''}
>
...
...
@@ -23,78 +22,78 @@ class TodoWidget {
</li>
'''
);
Element
contentElement
=
element
.
querySelector
(
'.todo-content'
);
InputElement
editElement
=
element
.
querySelector
(
'.edit'
);
toggleElement
=
element
.
querySelector
(
'.toggle'
);
toggleElement
.
onClick
.
listen
((
_
)
{
toggle
();
todoApp
.
updateCounts
();
todoApp
.
save
();
});
contentElement
.
onDoubleClick
.
listen
((
_
)
{
element
.
classes
.
add
(
'editing'
);
editElement
.
selectionStart
=
todo
.
title
.
length
;
editElement
.
focus
();
});
void
removeTodo
()
{
element
.
remove
();
todoApp
.
removeTodo
(
this
);
todoApp
.
updateFooterDisplay
();
}
element
.
querySelector
(
'.destroy'
).
onClick
.
listen
((
_
)
{
removeTodo
();
todoApp
.
save
();
});
void
doneEditing
()
{
editElement
.
value
=
editElement
.
value
.
trim
();
todo
.
title
=
editElement
.
value
;
if
(
todo
.
title
.
isNotEmpty
)
{
contentElement
.
text
=
todo
.
title
;
element
.
classes
.
remove
(
'editing'
);
}
else
{
removeTodo
();
}
todoApp
.
save
();
}
void
undoEditing
()
{
element
.
classes
.
remove
(
'editing'
);
editElement
.
value
=
todo
.
title
;
}
editElement
..
onKeyDown
.
listen
((
KeyboardEvent
e
)
{
switch
(
e
.
keyCode
)
{
case
KeyCode
.
ENTER
:
doneEditing
();
break
;
case
KeyCode
.
ESC
:
undoEditing
();
break
;
}
})
..
onBlur
.
listen
((
_
)
=>
doneEditing
());
return
element
;
}
void
set
visible
(
bool
visible
)
{
element
.
style
.
display
=
visible
?
'block'
:
'none'
;
}
void
toggle
()
{
todo
.
completed
=
!
todo
.
completed
;
toggleElement
.
checked
=
todo
.
completed
;
if
(
todo
.
completed
)
{
element
.
classes
.
add
(
'completed'
);
}
else
{
element
.
classes
.
remove
(
'completed'
);
}
}
Element
contentElement
=
element
.
querySelector
(
'.todo-content'
);
InputElement
editElement
=
element
.
querySelector
(
'.edit'
);
toggleElement
=
element
.
querySelector
(
'.toggle'
);
toggleElement
.
onClick
.
listen
((
_
)
{
toggle
();
todoApp
.
updateCounts
();
todoApp
.
save
();
});
contentElement
.
onDoubleClick
.
listen
((
_
)
{
element
.
classes
.
add
(
'editing'
);
editElement
.
selectionStart
=
todo
.
title
.
length
;
editElement
.
focus
();
});
void
removeTodo
()
{
element
.
remove
();
todoApp
.
removeTodo
(
this
);
todoApp
.
updateFooterDisplay
();
}
element
.
querySelector
(
'.destroy'
).
onClick
.
listen
((
_
)
{
removeTodo
();
todoApp
.
save
();
});
void
doneEditing
()
{
editElement
.
value
=
editElement
.
value
.
trim
();
todo
.
title
=
editElement
.
value
;
if
(
todo
.
title
.
isNotEmpty
)
{
contentElement
.
text
=
todo
.
title
;
element
.
classes
.
remove
(
'editing'
);
}
else
{
removeTodo
();
}
todoApp
.
save
();
}
void
undoEditing
()
{
element
.
classes
.
remove
(
'editing'
);
editElement
.
value
=
todo
.
title
;
}
editElement
..
onKeyDown
.
listen
((
KeyboardEvent
e
)
{
switch
(
e
.
keyCode
)
{
case
KeyCode
.
ENTER
:
doneEditing
();
break
;
case
KeyCode
.
ESC
:
undoEditing
();
break
;
}
})
..
onBlur
.
listen
((
_
)
=>
doneEditing
());
return
element
;
}
void
set
visible
(
bool
visible
)
{
element
.
style
.
display
=
visible
?
'block'
:
'none'
;
}
void
toggle
()
{
todo
.
completed
=
!
todo
.
completed
;
toggleElement
.
checked
=
todo
.
completed
;
if
(
todo
.
completed
)
{
element
.
classes
.
add
(
'completed'
);
}
else
{
element
.
classes
.
remove
(
'completed'
);
}
}
}
examples/vanilladart/web/dart/app.dart
View file @
cbbdbae6
library
todomvc
;
import
'dart:html'
show
Element
,
InputElement
,
KeyCode
,
KeyboardEvent
,
querySelector
,
window
;
show
Element
,
InputElement
,
KeyCode
,
KeyboardEvent
,
querySelector
,
window
;
import
'dart:convert'
show
HtmlEscape
,
JSON
;
import
'package:todomvc_vanilladart/models.dart'
;
import
'package:todomvc_vanilladart/uuid.dart'
;
...
...
@@ -10,5 +10,5 @@ part 'TodoWidget.dart';
part
'TodoApp.dart'
;
void
main
(
)
{
new
TodoApp
();
new
TodoApp
();
}
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