-
Notifications
You must be signed in to change notification settings - Fork 13
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
26 changed files
with
1,070 additions
and
33 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
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
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
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 |
---|---|---|
@@ -0,0 +1,72 @@ | ||
'use strict'; | ||
|
||
import dispatcher from './dispatcher'; | ||
|
||
export const add = text => { | ||
dispatcher.dispatch({ | ||
type: 'ADD_TODO', | ||
content: text | ||
}); | ||
}; | ||
|
||
export const remove = (id) => { | ||
dispatcher.dispatch({ | ||
type: 'DELETE_TODO', | ||
id | ||
}); | ||
}; | ||
|
||
export const compelete = (id) => { | ||
dispatcher.dispatch({ | ||
type: 'COMPLETE_TODO', | ||
id | ||
}); | ||
}; | ||
|
||
export const edit = (id) => { | ||
dispatcher.dispatch({ | ||
type: 'EDIT_TODO', | ||
id | ||
}); | ||
}; | ||
|
||
export const update = (data) => { | ||
dispatcher.dispatch({ | ||
type: 'UPDATE_TODO', | ||
id: data.id, | ||
content: data.value | ||
}); | ||
}; | ||
|
||
export const updateItem = (data) => { | ||
dispatcher.dispatch({ | ||
type: 'UPDATE_ITEM_TODO', | ||
id: data.id, | ||
content: data.value | ||
}); | ||
}; | ||
|
||
export const completedAll = () => { | ||
dispatcher.dispatch({ | ||
type: 'COMPLETE_ALL' | ||
}); | ||
}; | ||
|
||
export const uncompletedAll = () => { | ||
dispatcher.dispatch({ | ||
type: 'UNCOMPLETE_ALL' | ||
}); | ||
}; | ||
|
||
export const clearCompleted = () => { | ||
dispatcher.dispatch({ | ||
type: 'CLEAR_COMPLETED' | ||
}); | ||
}; | ||
|
||
export const setVisibilityFilter = (hash) => { | ||
dispatcher.dispatch({ | ||
type: 'SET_VISIBILITY_FILTER', | ||
hash | ||
}); | ||
}; |
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 |
---|---|---|
@@ -0,0 +1,29 @@ | ||
'use strict'; | ||
|
||
import { | ||
Container | ||
} from 'flux/utils'; | ||
|
||
import todoStore from './store/todo'; | ||
import typeStore from './store/type'; | ||
import View from './view.jsx'; | ||
import * as actions from './actions'; | ||
|
||
function getStores() { | ||
return [ | ||
todoStore, | ||
typeStore | ||
]; | ||
} | ||
|
||
function getState() { | ||
return { | ||
todos: todoStore.getState(), | ||
hash: typeStore.getState(), | ||
actions: { | ||
...actions | ||
} | ||
}; | ||
} | ||
|
||
export default Container.createFunctional(View, getStores, getState); |
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 |
---|---|---|
@@ -0,0 +1,7 @@ | ||
'use strict'; | ||
|
||
import { | ||
Dispatcher | ||
} from 'flux'; | ||
|
||
export default new Dispatcher(); |
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 |
---|---|---|
@@ -0,0 +1,21 @@ | ||
<!DOCTYPE html> | ||
<html> | ||
<head> | ||
<meta charset="UTF-8"> | ||
<meta content="width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=0" name="viewport"> | ||
<link rel="shortcut icon" href="../assets/images/logo.png" type="image/x-icon" /> | ||
<title>Flux • TodoMVC</title> | ||
</head> | ||
<body> | ||
<div id="app"> | ||
<script> | ||
var isOnline = !!~location.host.indexOf('github'); | ||
var script = document.createElement('script'); | ||
script.type = 'text/javascript'; | ||
script.src = (isOnline ? '//unpkg.com/dataflow-sample@latest' : '..') + '/dist/flux.js'; | ||
var head = document.getElementsByTagName('head')[0]; | ||
head.appendChild(script); | ||
</script> | ||
</div> | ||
</body> | ||
</html> |
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 |
---|---|---|
@@ -0,0 +1,8 @@ | ||
'use strict'; | ||
|
||
import React from 'react'; | ||
import ReactDOM from 'react-dom'; | ||
|
||
import App from './app'; | ||
|
||
ReactDOM.render(<App />, document.querySelector('#app')); |
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 |
---|---|---|
@@ -0,0 +1,115 @@ | ||
'use strict'; | ||
|
||
import { | ||
ReduceStore | ||
} from 'flux/utils'; | ||
|
||
import dispatcher from '../dispatcher'; | ||
|
||
const localStore = { | ||
get() { | ||
return JSON.parse(localStorage['enough-todo'] || '[]'); | ||
}, | ||
set(data) { | ||
localStorage['enough-todo'] = JSON.stringify(data); | ||
} | ||
}; | ||
|
||
class TodoStore extends ReduceStore { | ||
constructor() { | ||
super(dispatcher); | ||
} | ||
|
||
getInitialState() { | ||
return localStore.get(); | ||
} | ||
|
||
reduce(state, action) { | ||
switch (action.type) { | ||
case 'ADD_TODO': | ||
var res = [ | ||
...state, | ||
{ | ||
id: String(+new Date()), | ||
completed: false, | ||
content: action.content, | ||
editing: false | ||
} | ||
]; | ||
localStore.set(res); | ||
return res; | ||
case 'DELETE_TODO': | ||
var res = state.filter(item => item.id !== action.id); | ||
localStore.set(res); | ||
return res; | ||
case 'COMPLETE_TODO': | ||
var res = state.map(item => | ||
item.id === action.id | ||
? { | ||
...item, | ||
completed: !item.completed | ||
} | ||
: item | ||
); | ||
localStore.set(res); | ||
return res; | ||
case 'EDIT_TODO': | ||
var res = state.map(item => | ||
item.id === action.id | ||
? { | ||
...item, | ||
editing: true | ||
} | ||
: item | ||
); | ||
return res; | ||
case 'UPDATE_TODO': | ||
var res = state.map(item => | ||
item.id === action.id | ||
? { | ||
...item, | ||
content: action.content, | ||
editing: false | ||
} | ||
: item | ||
); | ||
localStore.set(res); | ||
return res; | ||
case 'UPDATE_ITEM_TODO': | ||
var res = state.map(item => | ||
item.id === action.id | ||
? { | ||
...item, | ||
content: action.content | ||
} | ||
: item | ||
); | ||
return res; | ||
case 'COMPLETE_ALL': | ||
var res = state.map(item => { | ||
return { | ||
...item, | ||
completed: true | ||
}; | ||
}); | ||
localStore.set(res); | ||
return res; | ||
case 'UNCOMPLETE_ALL': | ||
var res = state.map(item => { | ||
return { | ||
...item, | ||
completed: false | ||
}; | ||
}); | ||
localStore.set(res); | ||
return res; | ||
case 'CLEAR_COMPLETED': | ||
var res = state.filter(item => !item.completed); | ||
localStore.set(res); | ||
return res; | ||
} | ||
return state; | ||
} | ||
} | ||
|
||
export default new TodoStore(dispatcher); |
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 |
---|---|---|
@@ -0,0 +1,29 @@ | ||
'use strict'; | ||
|
||
import { | ||
ReduceStore | ||
} from 'flux/utils'; | ||
|
||
import dispatcher from '../dispatcher'; | ||
|
||
class TypeStore extends ReduceStore { | ||
constructor() { | ||
super(dispatcher); | ||
} | ||
|
||
getInitialState() { | ||
return location.hash.replace('#/', '') || 'all'; | ||
} | ||
|
||
reduce(state, action) { | ||
switch (action.type) { | ||
case 'SET_VISIBILITY_FILTER': | ||
state = action.hash; | ||
return state; | ||
} | ||
return state; | ||
} | ||
} | ||
|
||
export default new TypeStore(dispatcher); | ||
|
Oops, something went wrong.