Skip to content

Commit

Permalink
docs(ui): ClientAddonApi jsdoc
Browse files Browse the repository at this point in the history
  • Loading branch information
Guillaume Chau committed Apr 22, 2018
1 parent b0c0ff1 commit 5352094
Showing 1 changed file with 30 additions and 14 deletions.
44 changes: 30 additions & 14 deletions packages/@vue/cli-ui/src/util/ClientAddonApi.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,12 @@ export default class ClientAddonApi {
this.componentListeners = new Map()
}

/**
* Register a component globally.
*
* @param {string} id Component id
* @param {object} definition Component definition
*/
component (id, definition) {
this.components.set(id, definition)
const componentId = toComponentId(id)
Expand All @@ -21,6 +27,30 @@ export default class ClientAddonApi {
}
}

/**
* Add routes to vue-router under a /addon/<id> parent route.
* For example, addRoutes('foo', [ { path: '' }, { path: 'bar' } ])
* will add the /addon/foo/ and the /addon/foo/bar routes to vue-router.
*
* @param {string} id Routes pack id (generally the vue-cli plugin id)
* @param {any} routes vue-router route definitions
*/
addRoutes (id, routes) {
router.addRoutes([
{
path: `/addon/${id}`,
component: ProjectHome,
meta: {
needProject: true,
restore: true
},
children: routes
}
])
}

/* Internal */

getComponent (id) {
return this.components.get(id)
}
Expand All @@ -44,20 +74,6 @@ export default class ClientAddonApi {
}
})
}

addRoutes (id, routes) {
router.addRoutes([
{
path: `/addon/${id}`,
component: ProjectHome,
meta: {
needProject: true,
restore: true
},
children: routes
}
])
}
}

export function toComponentId (id) {
Expand Down

0 comments on commit 5352094

Please sign in to comment.