Last active
September 24, 2015 07:39
-
-
Save smontlouis/b8ad929a60ee10790c88 to your computer and use it in GitHub Desktop.
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
export function loadAllTodos() { | |
const promise = new Promise((resolve, reject) => { | |
Api.get() | |
.then(res => { | |
resolve(res); | |
}) | |
.catch(err => { | |
reject(err); | |
}) | |
}); | |
return dispatch(loadAllTodos, promise); | |
} |
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
router.run((Handler, routerState) => { | |
var p = Promise.all(routerState.routes | |
.filter(route => route.handler.fetchData) // définit fetchData | |
.map(route => { | |
return route.handler.fetchData(); | |
}) | |
); | |
p.then( resp => { | |
//I don't need resp, just update the state | |
appState = state.get().toJS() | |
const html = loadAppStateThenRenderHtml(Handler, appState); | |
const notFound = routerState.routes.some(route => route.name === 'not-found'); | |
const status = notFound ? 404 : 200; | |
res.status(status).send(html); | |
resolve(); | |
}); | |
}); |
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
case actions.loadAllTodos: | |
todosCursor(todos => { | |
return todos.update('list', list => list.withMutations(list => { | |
const newTodos = data; | |
newTodos.forEach(todo =>{ | |
list.push(new Todo({ | |
id: todo.id, | |
title: todo.title | |
})); | |
}); | |
})); | |
}); | |
break; |
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
class Todos extends Component { | |
fetchData(param) { | |
return actions.loadAllTodos(); | |
} | |
componentDidMount() { | |
this.fetchData(); | |
} | |
... |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment