Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save barneycarroll/667dd4b8efc36b7f0385b43a9308502a to your computer and use it in GitHub Desktop.
Save barneycarroll/667dd4b8efc36b7f0385b43a9308502a to your computer and use it in GitHub Desktop.
Cool async stuff
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