Skip to content

Instantly share code, notes, and snippets.

@smontlouis
Last active September 24, 2015 07:39
Show Gist options
  • Save smontlouis/b8ad929a60ee10790c88 to your computer and use it in GitHub Desktop.
Save smontlouis/b8ad929a60ee10790c88 to your computer and use it in GitHub Desktop.
export function loadAllTodos() {
const promise = new Promise((resolve, reject) => {
Api.get()
.then(res => {
resolve(res);
})
.catch(err => {
reject(err);
})
});
return dispatch(loadAllTodos, promise);
}
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();
});
});
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;
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