Skip to content

Instantly share code, notes, and snippets.

@taylorzane
Last active May 20, 2016 19:23
Show Gist options
  • Save taylorzane/c3eb0f0843a03d1f9939bcf5cf3b25db to your computer and use it in GitHub Desktop.
Save taylorzane/c3eb0f0843a03d1f9939bcf5cf3b25db to your computer and use it in GitHub Desktop.
const router = {
map (stuff) {
console.log(JSON.stringify(stuff))
}
}
const ComponentA = {
mixins: [{}]
}
const ComponentB = {
mixins: []
}
const ComponentC = {}
const myMixin = {
ready () {
console.log('foo')
}
}
const mixThemAll = (obj, ...mixins) => {
return Object.entries(obj).reduce((container, [key, data]) => {
if (data.component.mixins) {
if (data.component.mixins instanceof Array) {
data.component.mixins.push(...mixins)
} else {
throw new Error('component.mixins is not an Array!')
}
} else {
data.component.mixins = [...mixins]
}
container[key] = data
return container
}, {})
}
const routerComponents = {
'/a': {
component: ComponentA
},
'/b': {
component: ComponentB
},
'/c': {
component: {
template: '<h1>Hello</h1>'
}
}
}
router.map(mixThemAll(routerComponents, myMixin, myMixin, myMixin))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment