Skip to content

Commit

Permalink
var for local vars
Browse files Browse the repository at this point in the history
  • Loading branch information
MathieuLorber committed Oct 30, 2012
1 parent c715670 commit 180205a
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 12 deletions.
20 changes: 10 additions & 10 deletions labs/architecture-examples/dart/web/dart/TodoApp.dart
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -23,10 +23,10 @@ class TodoApp {
} }


void initLocalStorage() { void initLocalStorage() {
String jsonList = window.localStorage["todos-vanilladart"]; var jsonList = window.localStorage["todos-vanilladart"];
if (jsonList != null) { if (jsonList != null) {
try { try {
List<Map> todos = JSON.parse(jsonList); var todos = JSON.parse(jsonList);
for (Map todo in todos) { for (Map todo in todos) {
addTodo(new Todo.fromJson(todo)); addTodo(new Todo.fromJson(todo));
} }
Expand All @@ -37,11 +37,11 @@ class TodoApp {
} }


void initElementEventListeners() { void initElementEventListeners() {
InputElement newTodoElement = query('#new-todo'); var newTodoElement = query('#new-todo');


newTodoElement.on.keyPress.add((KeyboardEvent e) { newTodoElement.on.keyPress.add((KeyboardEvent e) {
if (e.keyIdentifier == KeyName.ENTER) { if (e.keyIdentifier == KeyName.ENTER) {
String title = newTodoElement.value.trim(); var title = newTodoElement.value.trim();
if (title != '') { if (title != '') {
addTodo(new Todo(UUID.createUuid(), title)); addTodo(new Todo(UUID.createUuid(), title));
newTodoElement.value = ''; newTodoElement.value = '';
Expand All @@ -52,7 +52,7 @@ class TodoApp {
}); });


checkAllCheckboxElement.on.click.add((Event e) { checkAllCheckboxElement.on.click.add((Event e) {
InputElement target = e.srcElement; var target = e.srcElement;
for (TodoWidget todoWidget in todoWidgets) { for (TodoWidget todoWidget in todoWidgets) {
if (todoWidget.todo.completed != target.checked) { if (todoWidget.todo.completed != target.checked) {
todoWidget.toggle(); todoWidget.toggle();
Expand All @@ -63,7 +63,7 @@ class TodoApp {
}); });


clearCompletedElement.on.click.add((MouseEvent e) { clearCompletedElement.on.click.add((MouseEvent e) {
List<TodoWidget> newList = new List<TodoWidget>(); var newList = new List<TodoWidget>();
for (TodoWidget todoWidget in todoWidgets) { for (TodoWidget todoWidget in todoWidgets) {
if (todoWidget.todo.completed) { if (todoWidget.todo.completed) {
todoWidget.element.remove(); todoWidget.element.remove();
Expand All @@ -78,7 +78,7 @@ class TodoApp {
} }


void addTodo(Todo todo) { void addTodo(Todo todo) {
TodoWidget todoWidget = new TodoWidget(this, todo); var todoWidget = new TodoWidget(this, todo);
todoWidgets.add(todoWidget); todoWidgets.add(todoWidget);
todoListElement.nodes.add(todoWidget.createElement()); todoListElement.nodes.add(todoWidget.createElement());
} }
Expand All @@ -97,14 +97,14 @@ class TodoApp {
} }


void updateCounts() { void updateCounts() {
int complete = 0; var complete = 0;
for (TodoWidget todoWidget in todoWidgets) { for (TodoWidget todoWidget in todoWidgets) {
if (todoWidget.todo.completed) { if (todoWidget.todo.completed) {
complete++; complete++;
} }
} }
checkAllCheckboxElement.checked = (complete == todoWidgets.length); checkAllCheckboxElement.checked = (complete == todoWidgets.length);
int left = todoWidgets.length - complete; var left = todoWidgets.length - complete;
countElement.innerHTML = '<b>${left}</b> item${left != 1 ? 's' : ''} left'; countElement.innerHTML = '<b>${left}</b> item${left != 1 ? 's' : ''} left';
if (complete == 0) { if (complete == 0) {
clearCompletedElement.style.display = 'none'; clearCompletedElement.style.display = 'none';
Expand Down Expand Up @@ -161,7 +161,7 @@ class TodoApp {
} }


void save() { void save() {
List<Todo> todos = new List<Todo>(); var todos = new List<Todo>();
for (TodoWidget todoWidget in todoWidgets) { for (TodoWidget todoWidget in todoWidgets) {
todos.add(todoWidget.todo); todos.add(todoWidget.todo);
} }
Expand Down
4 changes: 2 additions & 2 deletions labs/architecture-examples/dart/web/dart/TodoWidget.dart
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -20,8 +20,8 @@ class TodoWidget {
</li> </li>
'''); ''');


Element contentElement = element.query('.todo-content'); var contentElement = element.query('.todo-content');

This comment has been minimized.

Copy link
@sethladd

sethladd Oct 30, 2012

Collaborator

I would revert these, as .query() returns just an Element, but you know what the more specific element is. So, go ahead and use InputElement or DivElement or whatever here.

InputElement editElement = element.query('.edit'); var editElement = element.query('.edit');


toggleElement = element.query('.toggle'); toggleElement = element.query('.toggle');


Expand Down

2 comments on commit 180205a

@sethladd
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I like to annotate what query() returns, but otherwise your other changes look good!

@MathieuLorber
Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I also typed back target = event.srcElement, cause I had an editor warning for target.checked.

Please sign in to comment.