Skip to content

Commit 24ea28f

Browse files
committed
add a build step
1 parent b5a867a commit 24ea28f

File tree

4 files changed

+95
-12
lines changed

4 files changed

+95
-12
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1 +1,2 @@
11
node_modules
2+
/index.js

package-lock.json

Lines changed: 78 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,10 @@
88
"index.d.ts"
99
],
1010
"scripts": {
11-
"test": "jest"
11+
"test": "jest",
12+
"build": "buble src/index.js > index.js",
13+
"pretest": "npm run build",
14+
"prepublishOnly": "npm run build"
1215
},
1316
"repository": {
1417
"type": "git",
@@ -26,6 +29,7 @@
2629
},
2730
"homepage": "https://github.com/vuejs/vuex-router-sync#readme",
2831
"devDependencies": {
32+
"buble": "^0.15.2",
2933
"jest": "^20.0.4",
3034
"vue": "^2.3.3",
3135
"vue-router": "^2.0.0",

index.js renamed to src/index.js

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,24 +1,24 @@
11
exports.sync = function (store, router, options) {
2-
var moduleName = (options || {}).moduleName || 'route'
2+
const moduleName = (options || {}).moduleName || 'route'
33

44
store.registerModule(moduleName, {
55
namespaced: true,
66
state: cloneRoute(router.currentRoute),
77
mutations: {
8-
'ROUTE_CHANGED': function (state, transition) {
8+
'ROUTE_CHANGED' (state, transition) {
99
store.state[moduleName] = cloneRoute(transition.to, transition.from)
1010
}
1111
}
1212
})
1313

14-
var isTimeTraveling = false
15-
var currentPath
14+
let isTimeTraveling = false
15+
let currentPath
1616

1717
// sync router on store change
18-
var storeUnwatch = store.watch(
19-
function (state) { return state[moduleName] },
20-
function (route) {
21-
var fullPath = route.fullPath
18+
const storeUnwatch = store.watch(
19+
state => state[moduleName],
20+
route => {
21+
const { fullPath } = route
2222
if (fullPath === currentPath) {
2323
return
2424
}
@@ -32,13 +32,13 @@ exports.sync = function (store, router, options) {
3232
)
3333

3434
// sync store on router navigation
35-
var afterEachUnHook = router.afterEach(function (to, from) {
35+
const afterEachUnHook = router.afterEach((to, from) => {
3636
if (isTimeTraveling) {
3737
isTimeTraveling = false
3838
return
3939
}
4040
currentPath = to.fullPath
41-
store.commit(moduleName + '/ROUTE_CHANGED', { to: to, from: from })
41+
store.commit(moduleName + '/ROUTE_CHANGED', { to, from })
4242
})
4343

4444
return function unsync () {
@@ -58,7 +58,7 @@ exports.sync = function (store, router, options) {
5858
}
5959

6060
function cloneRoute (to, from) {
61-
var clone = {
61+
const clone = {
6262
name: to.name,
6363
path: to.path,
6464
hash: to.hash,

0 commit comments

Comments
 (0)