Skip to content

Commit

Permalink
feat: export nextTick (#401)
Browse files Browse the repository at this point in the history
* feat: export nextTick

* chore: update
  • Loading branch information
antfu committed Jun 24, 2020
1 parent 58d8d9a commit d70c904
Show file tree
Hide file tree
Showing 3 changed files with 41 additions and 0 deletions.
1 change: 1 addition & 0 deletions src/index.ts
Expand Up @@ -21,6 +21,7 @@ if (currentVue && typeof window !== 'undefined' && window.Vue) {
}

export default plugin
export { nextTick } from './nextTick'
export { default as createElement } from './createElement'
export { SetupContext }
export {
Expand Down
11 changes: 11 additions & 0 deletions src/nextTick.ts
@@ -0,0 +1,11 @@
import Vue from 'vue'
import { currentVue } from './runtimeContext'

type NextTick = Vue['$nextTick']

export const nextTick: NextTick = function nextTick(
this: ThisType<NextTick>,
...args: Parameters<NextTick>
) {
return currentVue?.nextTick.bind(this, args)
} as any
29 changes: 29 additions & 0 deletions test/misc.spec.js
@@ -0,0 +1,29 @@
const Vue = require('vue/dist/vue.common.js')
const { ref, nextTick } = require('../src')

describe('nextTick', () => {
it('should works', () => {
const vm = new Vue({
template: `<div>{{a}}</div>`,
setup() {
return {
a: ref(1),
}
},
}).$mount()

expect(vm.$el.textContent).toBe('1')
vm.a = 2
expect(vm.$el.textContent).toBe('1')

nextTick(() => {
expect(vm.$el.textContent).toBe('2')
vm.a = 3
expect(vm.$el.textContent).toBe('2')

nextTick(() => {
expect(vm.$el.textContent).toBe('3')
})
})
})
})

0 comments on commit d70c904

Please sign in to comment.