Skip to content

Commit 6959359

Browse files
committed
fix: remove promise and directly inject segment
1 parent 1186c25 commit 6959359

File tree

3 files changed

+307
-273
lines changed

3 files changed

+307
-273
lines changed

lib/plugin.js

+8-9
Original file line numberDiff line numberDiff line change
@@ -7,25 +7,24 @@ const SEGMENT_USE_ROUTER = <%= options.useRouter %>
77
const SEGMENT_SETTINGS = <%= JSON.stringify(options.settings) %>
88

99
export default function (context, inject) {
10+
const { app, store } = context
1011

1112
const options = {
1213
writeKey: SEGMENT_WRITE_KEY,
1314
disabled: SEGMENT_DISABLED,
1415
settings: SEGMENT_SETTINGS
1516
}
1617

17-
if (SEGMENT_USE_ROUTER) {
18-
options.router = context.app.router
18+
if (SEGMENT_USE_ROUTER && app.router) {
19+
options.router = app.router
1920
}
2021

2122
Vue.use(Segment, options)
2223

23-
return new Promise((resolve) => {
24-
Vue.$segment.ready(() => {
25-
context.$segment = Vue.$segment
26-
inject('segment', Vue.$segment)
27-
resolve()
28-
})
29-
})
24+
if (store) {
25+
store.$segment = Vue.$segment
26+
}
3027

28+
context.$segment = Vue.$segment
29+
inject('segment', Vue.$segment)
3130
}

test/fixture/pages/index.vue

+3
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,9 @@ export default {
2020
methods: {
2121
loadSegment () {
2222
this.$segment.load(process.env.SEGMENT_WRITE_KEY)
23+
this.$segment.ready(() => {
24+
console.log('ready')
25+
})
2326
}
2427
}
2528
}

0 commit comments

Comments
 (0)