Commit 2a4d9f90 authored by Pascal Hartig's avatar Pascal Hartig

Merge branch 'pr/711' into gh-pages

Close #711
parents cf53b0fd f72e4c1c
...@@ -3,15 +3,15 @@ part of todomvc; ...@@ -3,15 +3,15 @@ part of todomvc;
class TodoApp { class TodoApp {
List<TodoWidget> todoWidgets = new List<TodoWidget>(); List<TodoWidget> todoWidgets = new List<TodoWidget>();
Element todoListElement = query('#todo-list'); Element todoListElement = querySelector('#todo-list');
Element mainElement = query('#main'); Element mainElement = querySelector('#main');
InputElement checkAllCheckboxElement = query('#toggle-all'); InputElement checkAllCheckboxElement = querySelector('#toggle-all');
Element footerElement = query('#footer'); Element footerElement = querySelector('#footer');
Element countElement = query('#todo-count'); Element countElement = querySelector('#todo-count');
Element clearCompletedElement = query('#clear-completed'); Element clearCompletedElement = querySelector('#clear-completed');
Element showAllElement = query('#filters a[href="#/"]'); Element showAllElement = querySelector('#filters a[href="#/"]');
Element showActiveElement = query('#filters a[href="#/active"]'); Element showActiveElement = querySelector('#filters a[href="#/active"]');
Element showCompletedElement = query('#filters a[href="#/completed"]'); Element showCompletedElement = querySelector('#filters a[href="#/completed"]');
TodoApp() { TodoApp() {
initLocalStorage(); initLocalStorage();
...@@ -26,7 +26,7 @@ class TodoApp { ...@@ -26,7 +26,7 @@ class TodoApp {
var jsonList = window.localStorage['todos-vanilladart']; var jsonList = window.localStorage['todos-vanilladart'];
if (jsonList != null) { if (jsonList != null) {
try { try {
var todos = JSON.parse(jsonList); var todos = JSON.decode(jsonList);
for (Map todo in todos) { for (Map todo in todos) {
addTodo(new Todo.fromJson(todo)); addTodo(new Todo.fromJson(todo));
} }
...@@ -37,7 +37,7 @@ class TodoApp { ...@@ -37,7 +37,7 @@ class TodoApp {
} }
void initElementEventListeners() { void initElementEventListeners() {
InputElement newTodoElement = query('#new-todo'); InputElement newTodoElement = querySelector('#new-todo');
newTodoElement.onKeyPress.listen((KeyboardEvent e) { newTodoElement.onKeyPress.listen((KeyboardEvent e) {
if (e.keyCode == KeyCode.ENTER) { if (e.keyCode == KeyCode.ENTER) {
...@@ -160,6 +160,6 @@ class TodoApp { ...@@ -160,6 +160,6 @@ class TodoApp {
for (TodoWidget todoWidget in todoWidgets) { for (TodoWidget todoWidget in todoWidgets) {
todos.add(todoWidget.todo); todos.add(todoWidget.todo);
} }
window.localStorage['todos-vanilladart'] = JSON.stringify(todos); window.localStorage['todos-vanilladart'] = JSON.encode(todos);
} }
} }
...@@ -2,7 +2,7 @@ library todomvc; ...@@ -2,7 +2,7 @@ library todomvc;
import 'dart:html'; import 'dart:html';
import 'dart:math'; import 'dart:math';
import 'dart:json' as JSON; import 'dart:convert';
part 'TodoWidget.dart'; part 'TodoWidget.dart';
part 'TodoApp.dart'; part 'TodoApp.dart';
...@@ -24,6 +24,7 @@ class Todo { ...@@ -24,6 +24,7 @@ class Todo {
completed = json['completed']; completed = json['completed'];
} }
// this is automatically called by JSON.encode
Map toJson() { Map toJson() {
return {'id': id, 'title': title, 'completed': completed}; return {'id': id, 'title': title, 'completed': completed};
} }
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment