Last active
May 20, 2016 19:23
-
-
Save taylorzane/c3eb0f0843a03d1f9939bcf5cf3b25db 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
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