Last active
February 2, 2017 16:07
-
-
Save barneycarroll/667dd4b8efc36b7f0385b43a9308502a to your computer and use it in GitHub Desktop.
Cool async stuff
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
import m from 'mithril' | |
import store from '../../store' | |
import {loadUsers} from '../../data/users/actions' | |
import layout from '../../components/layout' | |
if (typeof require.ensure !== 'function') require.ensure = (d, c) => c(require) | |
async function getJs(){ | |
return (await require('./users.js')).default | |
} | |
async function getData(){ | |
return window.__STATE_IS_PRELOADED__ || store().dispatch(loadUsers()) | |
} | |
export default { | |
async onmatch () { | |
const [ users, ] = await Promise.all([ | |
getData(), | |
getJs() | |
]) | |
this.users = users | |
window.__STATE_IS_PRELOADED__ = false | |
}, | |
render (vnode) { | |
this.title = 'Users - Mithril' | |
this.description = 'Users Page' | |
document.title = this.title | |
return m(layout, vnode.attrs, m(this.users, vnode.attrs)) | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment