Skip to content

Commit d70c904

Browse files
authoredJun 24, 2020
feat: export nextTick (#401)
* feat: export nextTick * chore: update
1 parent 58d8d9a commit d70c904

File tree

3 files changed

+41
-0
lines changed

3 files changed

+41
-0
lines changed
 

‎src/index.ts

+1
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ if (currentVue && typeof window !== 'undefined' && window.Vue) {
2121
}
2222

2323
export default plugin
24+
export { nextTick } from './nextTick'
2425
export { default as createElement } from './createElement'
2526
export { SetupContext }
2627
export {

‎src/nextTick.ts

+11
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
import Vue from 'vue'
2+
import { currentVue } from './runtimeContext'
3+
4+
type NextTick = Vue['$nextTick']
5+
6+
export const nextTick: NextTick = function nextTick(
7+
this: ThisType<NextTick>,
8+
...args: Parameters<NextTick>
9+
) {
10+
return currentVue?.nextTick.bind(this, args)
11+
} as any

‎test/misc.spec.js

+29
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
const Vue = require('vue/dist/vue.common.js')
2+
const { ref, nextTick } = require('../src')
3+
4+
describe('nextTick', () => {
5+
it('should works', () => {
6+
const vm = new Vue({
7+
template: `<div>{{a}}</div>`,
8+
setup() {
9+
return {
10+
a: ref(1),
11+
}
12+
},
13+
}).$mount()
14+
15+
expect(vm.$el.textContent).toBe('1')
16+
vm.a = 2
17+
expect(vm.$el.textContent).toBe('1')
18+
19+
nextTick(() => {
20+
expect(vm.$el.textContent).toBe('2')
21+
vm.a = 3
22+
expect(vm.$el.textContent).toBe('2')
23+
24+
nextTick(() => {
25+
expect(vm.$el.textContent).toBe('3')
26+
})
27+
})
28+
})
29+
})

0 commit comments

Comments
 (0)
Please sign in to comment.