Skip to content

Commit

Permalink
refactor(windowTitlePlugin): route configuration change
Browse files Browse the repository at this point in the history
BREAKING CHANGE:

Before: the plugin expected a property {data: title}
Now: the plugin expects a property {windowTitlePlugin: title}
  • Loading branch information
AoDev committed May 14, 2019
1 parent 2e63744 commit fbf7ce9
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 8 deletions.
8 changes: 4 additions & 4 deletions src/plugins/windowTitlePlugin.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
*/
function setWindowTitleFromRouter (router, options) {
const routeConfig = router.routes[router.route]
const titleConfig = routeConfig && routeConfig.data && routeConfig.data.title
const titleConfig = routeConfig && routeConfig.windowTitlePlugin && routeConfig.windowTitlePlugin.title

if (typeof titleConfig === 'function') {
let title = titleConfig(router)
Expand All @@ -24,7 +24,7 @@ function setWindowTitleFromRouter (router, options) {
* Register the plugin with a router instance.
*
* How to use:
* - Add a data.title field to any route config.
* - Add a windowTitlePlugin.title field to any route config.
* - title can be either a string or a function.
* - if it's a function, it will be called with the router as argument.
*
Expand All @@ -33,10 +33,10 @@ function setWindowTitleFromRouter (router, options) {
* // myroutes.js
* {
* '/some-page': {
* data: {title: 'Some page'}
* windowTitlePlugin: {title: 'Some page'}
* },
* '/some-other-page': {
* data: {
* windowTitlePlugin: {
* title (router) {
* const {appStore} = router.app
* return `Some other page - ${appStore.someValue}`
Expand Down
8 changes: 4 additions & 4 deletions src/plugins/windowTitlePlugin.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,17 +5,17 @@ const titleSpy = jest.fn()

const routes = {
'/': {
data: {
windowTitlePlugin: {
title: 'Root',
},
},
'/some-page': {
data: {
windowTitlePlugin: {
title: 'Some page',
},
},
'/some-other-page': {
data: {
windowTitlePlugin: {
title (router) {
titleSpy(router)
return 'Some other page'
Expand Down Expand Up @@ -62,7 +62,7 @@ describe('WindowTitlePlugin', () => {
const unregister = windowTitlePlugin.register(routerMock)
unregister()
const spyArgs = routerMock.off.mock.calls[0]
expect(spyArgs[0]).toBe('nav')
expect(spyArgs[0]).toBe('afterNav')
// fragile way to test that it passed the right handler
expect(spyArgs[1].name.endsWith('setWindowTitleFromRouter')).toBe(true)
})
Expand Down

0 comments on commit fbf7ce9

Please sign in to comment.