Skip to content

Commit 3443704

Browse files
committed
Uninstall forceNextTick and added a simple doubleRequestAnimationFrame function
1 parent 2399b01 commit 3443704

File tree

3 files changed

+12
-19
lines changed

3 files changed

+12
-19
lines changed

package-lock.json

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

package.json

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,6 @@
5858
"jest": "^25.1.0",
5959
"jest-serializer-vue": "^2.0.2",
6060
"jest-transform-stub": "^2.0.0",
61-
"vue-jest": "^3.0.5",
6261
"rollup": "^1.29.0",
6362
"rollup-plugin-babel": "^3.0.4",
6463
"rollup-plugin-buble": "^0.19.8",
@@ -72,7 +71,7 @@
7271
"standard-version": "^7.1.0",
7372
"surge": "^0.21.3",
7473
"vue": "^2.6.11",
75-
"vue-force-next-tick": "^1.0.3",
74+
"vue-jest": "^3.0.5",
7675
"vue-template-compiler": "^2.6.11"
7776
}
7877
}

src/index.js

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
1-
import VueForceNextTick from 'vue-force-next-tick'
21
import { OPTIONS } from './constants'
32
import VueAnnouncer from './vue-announcer.vue'
43

4+
const draf = (cb) => requestAnimationFrame(() => requestAnimationFrame(cb))
5+
56
export default function install (Vue, options = {}, router = null) {
67
options = { ...OPTIONS, ...options }
78

8-
Vue.use(VueForceNextTick)
99
Vue.component('VueAnnouncer', VueAnnouncer)
1010
Vue.prototype.$announcer = {
1111
options,
@@ -16,7 +16,7 @@ export default function install (Vue, options = {}, router = null) {
1616
if (politeness) {
1717
this.data.politeness = politeness
1818
}
19-
Vue.$forceNextTick(() => {
19+
draf(() => {
2020
this.data.content = message
2121
})
2222
}
@@ -40,15 +40,18 @@ export default function install (Vue, options = {}, router = null) {
4040
// If set the router, will be announced the change of route
4141
if (router) {
4242
router.afterEach(to => {
43-
const msg = to.meta.announcer.message || document.title.trim()
44-
const complement = to.meta.announcer.complementRoute || options.complementRoute
45-
const politeness = to.meta.announcer.politeness || null
46-
Vue.prototype.$announcer.set(`${msg} ${complement}`, politeness)
43+
draf(() => { // Resolves the problem of getting the correct title when the meta announcer is not passed
44+
const announcer = to.meta.announcer || {}
45+
const msg = announcer.message || document.title.trim()
46+
const complement = announcer.complementRoute || options.complementRoute
47+
const politeness = announcer.politeness || null
48+
Vue.prototype.$announcer.set(`${msg} ${complement}`, politeness)
49+
})
4750
})
4851
}
4952
}
5053

51-
// auto install
54+
// Auto install
5255
if (typeof window !== 'undefined' && typeof window.Vue !== 'undefined') {
5356
window.Vue.use(install)
5457
}

0 commit comments

Comments
 (0)