forked from tastejs/todomvc
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request tastejs#616 from stephenplusplus/flight-bug
(flight) bug with clearCompleted.
- Loading branch information
Showing
12 changed files
with
355 additions
and
399 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,38 +1,26 @@ | ||
/*global define */ | ||
'use strict'; | ||
|
||
define( | ||
[ | ||
'./data/todos', | ||
'./data/stats', | ||
'./ui/new_item', | ||
'./ui/todo_list', | ||
'./ui/stats', | ||
'./ui/main_selector', | ||
'./ui/toggle_all' | ||
], | ||
define([ | ||
'./data/todos', | ||
'./data/stats', | ||
'./ui/new_item', | ||
'./ui/todo_list', | ||
'./ui/stats', | ||
'./ui/main_selector', | ||
'./ui/toggle_all' | ||
], function (TodosData, StatsData, NewItemUI, TodoListUI, StatsUI, MainSelectorUI, ToggleAllUI) { | ||
var initialize = function () { | ||
StatsData.attachTo(document); | ||
TodosData.attachTo(document); | ||
NewItemUI.attachTo('#new-todo'); | ||
MainSelectorUI.attachTo('#main'); | ||
StatsUI.attachTo('#footer'); | ||
ToggleAllUI.attachTo('#toggle-all'); | ||
TodoListUI.attachTo('#todo-list'); | ||
}; | ||
|
||
function ( | ||
TodosData, | ||
StatsData, | ||
NewItemUI, | ||
TodoListUI, | ||
StatsUI, | ||
MainSelectorUI, | ||
ToggleAllUI) { | ||
|
||
var initialize = function () { | ||
StatsData.attachTo(document); | ||
TodosData.attachTo(document); | ||
NewItemUI.attachTo('#new-todo'); | ||
MainSelectorUI.attachTo('#main'); | ||
StatsUI.attachTo('#footer'); | ||
ToggleAllUI.attachTo('#toggle-all'); | ||
TodoListUI.attachTo('#todo-list'); | ||
}; | ||
|
||
return { | ||
initialize: initialize | ||
}; | ||
} | ||
); | ||
return { | ||
initialize: initialize | ||
}; | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,39 +1,35 @@ | ||
/*global define */ | ||
'use strict'; | ||
|
||
define( | ||
[ | ||
'flight/component', | ||
'../store' | ||
], | ||
define([ | ||
'flight/component', | ||
'../store' | ||
], function (defineComponent, dataStore) { | ||
function stats() { | ||
this.recount = function () { | ||
var todos = dataStore.all(); | ||
var all = todos.length; | ||
var remaining = todos.reduce(function (memo, each) { | ||
return memo += each.completed ? 0 : 1; | ||
}, 0); | ||
|
||
function (defineComponent, dataStore) { | ||
return defineComponent(stats); | ||
this.trigger('dataStatsCounted', { | ||
all: all, | ||
remaining: remaining, | ||
completed: all - remaining, | ||
filter: localStorage.getItem('filter') || '' | ||
}); | ||
}; | ||
|
||
function stats() { | ||
this.recount = function () { | ||
var todos = dataStore.all(); | ||
var all = todos.length; | ||
var remaining = todos.reduce(function (memo, each) { | ||
return memo += each.completed ? 0 : 1; | ||
}, 0); | ||
this.after('initialize', function () { | ||
this.on(document, 'dataTodosLoaded', this.recount); | ||
this.on(document, 'dataTodoAdded', this.recount); | ||
this.on(document, 'dataTodoRemoved', this.recount); | ||
this.on(document, 'dataTodoToggled', this.recount); | ||
this.on(document, 'dataClearedCompleted', this.recount); | ||
this.on(document, 'dataTodoToggledAll', this.recount); | ||
}); | ||
} | ||
|
||
this.trigger('dataStatsCounted', { | ||
all: all, | ||
remaining: remaining, | ||
completed: all - remaining, | ||
filter: localStorage.getItem('filter') || '' | ||
}); | ||
}; | ||
|
||
this.after('initialize', function () { | ||
this.on(document, 'dataTodosLoaded', this.recount); | ||
this.on(document, 'dataTodoAdded', this.recount); | ||
this.on(document, 'dataTodoRemoved', this.recount); | ||
this.on(document, 'dataTodoToggled', this.recount); | ||
this.on(document, 'dataClearedCompleted', this.recount); | ||
this.on(document, 'dataTodoToggledAll', this.recount); | ||
}); | ||
} | ||
} | ||
); | ||
return defineComponent(stats); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,105 +1,99 @@ | ||
/*global define */ | ||
'use strict'; | ||
|
||
define( | ||
[ | ||
'flight/component', | ||
'../store' | ||
], | ||
|
||
function (defineComponent, dataStore) { | ||
return defineComponent(todos); | ||
|
||
function todos() { | ||
var filter; | ||
|
||
this.add = function (e, data) { | ||
var todo = dataStore.save({ | ||
title: data.title, | ||
completed: false | ||
}); | ||
|
||
this.trigger('dataTodoAdded', { todo: todo, filter: filter }); | ||
}; | ||
|
||
this.remove = function (e, data) { | ||
var todo = dataStore.destroy(data.id); | ||
|
||
this.trigger('dataTodoRemoved', todo); | ||
}; | ||
define([ | ||
'flight/component', | ||
'../store' | ||
], function (defineComponent, dataStore) { | ||
function todos() { | ||
var filter; | ||
|
||
this.add = function (e, data) { | ||
var todo = dataStore.save({ | ||
title: data.title, | ||
completed: false | ||
}); | ||
|
||
this.load = function (e, data) { | ||
var todos; | ||
this.trigger('dataTodoAdded', { todo: todo, filter: filter }); | ||
}; | ||
|
||
filter = localStorage.getItem('filter'); | ||
todos = this.find(); | ||
this.trigger('dataTodosLoaded', { todos: todos }); | ||
}; | ||
this.remove = function (e, data) { | ||
var todo = dataStore.destroy(data.id); | ||
|
||
this.update = function (e, data) { | ||
dataStore.save(data); | ||
}; | ||
this.trigger('dataTodoRemoved', todo); | ||
}; | ||
|
||
this.toggleCompleted = function (e, data) { | ||
var eventType; | ||
var todo = dataStore.get(data.id); | ||
this.load = function () { | ||
var todos; | ||
|
||
todo.completed = !todo.completed; | ||
dataStore.save(todo); | ||
filter = localStorage.getItem('filter'); | ||
todos = this.find(); | ||
this.trigger('dataTodosLoaded', { todos: todos }); | ||
}; | ||
|
||
eventType = filter ? 'dataTodoRemoved' : 'dataTodoToggled'; | ||
this.update = function (e, data) { | ||
dataStore.save(data); | ||
}; | ||
|
||
this.trigger(eventType, todo); | ||
}; | ||
this.toggleCompleted = function (e, data) { | ||
var eventType; | ||
var todo = dataStore.get(data.id); | ||
|
||
this.toggleAllCompleted = function (e, data) { | ||
dataStore.updateAll({ completed: data.completed }); | ||
this.trigger('dataTodoToggledAll', { todos: this.find(filter) }); | ||
}; | ||
todo.completed = !todo.completed; | ||
dataStore.save(todo); | ||
|
||
this.filter = function (e, data) { | ||
var todos; | ||
eventType = filter ? 'dataTodoRemoved' : 'dataTodoToggled'; | ||
|
||
localStorage.setItem('filter', data.filter); | ||
filter = data.filter; | ||
todos = this.find(); | ||
this.trigger(eventType, todo); | ||
}; | ||
|
||
this.trigger('dataTodosFiltered', { todos: todos }); | ||
}; | ||
this.toggleAllCompleted = function (e, data) { | ||
dataStore.updateAll({ completed: data.completed }); | ||
this.trigger('dataTodoToggledAll', { todos: this.find(filter) }); | ||
}; | ||
|
||
this.find = function () { | ||
var todos; | ||
this.filter = function (e, data) { | ||
var todos; | ||
|
||
if (filter) { | ||
todos = dataStore.find(function (each) { | ||
return (typeof each[filter] !== 'undefined') ? each.completed : !each.completed; | ||
}); | ||
} | ||
else { | ||
todos = dataStore.all(); | ||
} | ||
localStorage.setItem('filter', data.filter); | ||
filter = data.filter; | ||
todos = this.find(); | ||
|
||
return todos; | ||
}; | ||
this.trigger('dataTodosFiltered', { todos: todos }); | ||
}; | ||
|
||
this.clearCompleted = function () { | ||
var todos; | ||
this.find = function () { | ||
var todos; | ||
|
||
dataStore.destroyAll({ completed: true }); | ||
if (filter) { | ||
todos = dataStore.find(function (each) { | ||
return (typeof each[filter] !== 'undefined') ? each.completed : !each.completed; | ||
}); | ||
} else { | ||
todos = dataStore.all(); | ||
this.trigger('dataClearedCompleted', { todos: todos }); | ||
}; | ||
|
||
this.after('initialize', function () { | ||
this.on(document, 'uiAddRequested', this.add); | ||
this.on(document, 'uiUpdateRequested', this.update); | ||
this.on(document, 'uiRemoveRequested', this.remove); | ||
this.on(document, 'uiLoadRequested', this.load); | ||
this.on(document, 'uiToggleRequested', this.toggleCompleted); | ||
this.on(document, 'uiToggleAllRequested', this.toggleAllCompleted); | ||
this.on(document, 'uiClearRequested', this.clearCompleted); | ||
this.on(document, 'uiFilterRequested', this.filter); | ||
}); | ||
} | ||
} | ||
|
||
return todos; | ||
}; | ||
|
||
this.clearCompleted = function () { | ||
dataStore.destroyAll({ completed: true }); | ||
|
||
this.trigger('uiFilterRequested', { filter: filter }); | ||
this.trigger('dataClearedCompleted'); | ||
}; | ||
|
||
this.after('initialize', function () { | ||
this.on(document, 'uiAddRequested', this.add); | ||
this.on(document, 'uiUpdateRequested', this.update); | ||
this.on(document, 'uiRemoveRequested', this.remove); | ||
this.on(document, 'uiLoadRequested', this.load); | ||
this.on(document, 'uiToggleRequested', this.toggleCompleted); | ||
this.on(document, 'uiToggleAllRequested', this.toggleAllCompleted); | ||
this.on(document, 'uiClearRequested', this.clearCompleted); | ||
this.on(document, 'uiFilterRequested', this.filter); | ||
}); | ||
} | ||
); | ||
|
||
return defineComponent(todos); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,11 +1,9 @@ | ||
'use strict'; | ||
/*global define */ | ||
|
||
define( | ||
[ | ||
'depot' | ||
], | ||
'use strict'; | ||
|
||
function (depot) { | ||
return depot('todos', { idAttribute: 'id' }); | ||
} | ||
); | ||
define([ | ||
'depot' | ||
], function (depot) { | ||
return depot('todos', { idAttribute: 'id' }); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,24 +1,20 @@ | ||
/*global define */ | ||
'use strict'; | ||
|
||
define( | ||
[ | ||
'flight/component' | ||
], | ||
define([ | ||
'flight/component' | ||
], function (defineComponent) { | ||
function mainSelector() { | ||
this.toggle = function (e, data) { | ||
var toggle = data.all > 0; | ||
this.$node.toggle(toggle); | ||
}; | ||
|
||
function (defineComponent) { | ||
return defineComponent(mainSelector); | ||
|
||
function mainSelector() { | ||
this.toggle = function (e, data) { | ||
var toggle = data.all > 0; | ||
this.$node.toggle(toggle); | ||
}; | ||
|
||
this.after('initialize', function () { | ||
this.$node.hide(); | ||
this.on(document, 'dataStatsCounted', this.toggle); | ||
}); | ||
} | ||
this.after('initialize', function () { | ||
this.$node.hide(); | ||
this.on(document, 'dataStatsCounted', this.toggle); | ||
}); | ||
} | ||
); | ||
|
||
return defineComponent(mainSelector); | ||
}); |
Oops, something went wrong.