Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: export nextTick #401

Merged
merged 2 commits into from
Jun 24, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions src/index.ts
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
@@ -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)
pikax marked this conversation as resolved.
Show resolved Hide resolved
} as any
29 changes: 29 additions & 0 deletions test/misc.spec.js
Original file line number Diff line number Diff line change
@@ -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')
})
})
})
})