Skip to content

Commit 23e90f5

Browse files
authored
BREAKING CHANGE: rename createElement to h (#400)
1 parent a1792de commit 23e90f5

14 files changed

+29
-27
lines changed

src/apis/computed.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { getCurrentVue, getCurrentVM } from '../runtimeContext'
1+
import { getCurrentVue, getCurrentInstance } from '../runtimeContext'
22
import { createRef, Ref } from '../reactivity'
33
import { defineComponentInstance } from '../helper'
44
import { warn } from '../utils'
@@ -22,7 +22,7 @@ export function computed<T>(options: Option<T>): WritableComputedRef<T>
2222
export function computed<T>(
2323
options: Option<T>['get'] | Option<T>
2424
): ComputedRef<T> | WritableComputedRef<T> {
25-
const vm = getCurrentVM()
25+
const vm = getCurrentInstance()
2626
let get: Option<T>['get'], set: Option<T>['set'] | undefined
2727
if (typeof options === 'function') {
2828
get = options

src/apis/inject.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import { ComponentInstance } from '../component'
22
import { currentVMInFn } from '../helper'
33
import { hasOwn, warn } from '../utils'
4-
import { getCurrentVM } from '../runtimeContext'
4+
import { getCurrentInstance } from '../runtimeContext'
55

66
const NOT_FOUND = {}
77
export interface InjectionKey<T> extends Symbol {}
@@ -48,7 +48,7 @@ export function inject(
4848
return defaultValue
4949
}
5050

51-
const vm = getCurrentVM()
51+
const vm = getCurrentInstance()
5252
if (vm) {
5353
const val = resolveInject(key, vm)
5454
if (val !== NOT_FOUND) {

src/apis/lifecycle.ts

+6-2
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,10 @@
11
import { VueConstructor } from 'vue'
22
import { ComponentInstance } from '../component'
3-
import { getCurrentVue, setCurrentVM, getCurrentVM } from '../runtimeContext'
3+
import {
4+
getCurrentVue,
5+
setCurrentVM,
6+
getCurrentInstance,
7+
} from '../runtimeContext'
48
import { currentVMInFn } from '../helper'
59

610
const genName = (name: string) => `on${name[0].toUpperCase() + name.slice(1)}`
@@ -26,7 +30,7 @@ function injectHookOption(
2630

2731
function wrapHookCall(vm: ComponentInstance, fn: Function) {
2832
return (...args: any) => {
29-
let preVm = getCurrentVM()
33+
let preVm = getCurrentInstance()
3034
setCurrentVM(vm)
3135
try {
3236
return fn(...args)

src/apis/watch.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import { ComponentInstance } from '../component'
22
import { Ref, isRef, isReactive } from '../reactivity'
33
import { assert, logError, noopFn, warn, isFunction } from '../utils'
44
import { defineComponentInstance } from '../helper'
5-
import { getCurrentVM, getCurrentVue } from '../runtimeContext'
5+
import { getCurrentInstance, getCurrentVue } from '../runtimeContext'
66
import { WatcherPreFlushQueueKey, WatcherPostFlushQueueKey } from '../symbols'
77
import { ComputedRef } from './computed'
88

@@ -95,7 +95,7 @@ function getWatchEffectOption(options?: Partial<WatchOptions>): WatchOptions {
9595
}
9696

9797
function getWatcherVM() {
98-
let vm = getCurrentVM()
98+
let vm = getCurrentInstance()
9999
if (!vm) {
100100
if (!fallbackVM) {
101101
fallbackVM = defineComponentInstance(getCurrentVue())

src/createElement.ts

+3-3
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,9 @@ type CreateElement = Vue['$createElement']
77

88
let fallbackCreateElement: CreateElement
99

10-
const createElement: CreateElement = function createElement(...args: any) {
10+
export const createElement: CreateElement = function createElement(
11+
...args: any
12+
) {
1113
if (!currentVM) {
1214
warn('`createElement()` has been called outside of render function.')
1315
if (!fallbackCreateElement) {
@@ -20,5 +22,3 @@ const createElement: CreateElement = function createElement(...args: any) {
2022

2123
return currentVM.$createElement.apply(currentVM, args)
2224
} as any
23-
24-
export default createElement

src/helper.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
import Vue, { VNode, ComponentOptions, VueConstructor } from 'vue'
22
import { ComponentInstance } from './component'
3-
import { currentVue, getCurrentVM } from './runtimeContext'
3+
import { currentVue, getCurrentInstance } from './runtimeContext'
44
import { warn } from './utils'
55

66
export function currentVMInFn(hook: string): ComponentInstance | null {
7-
const vm = getCurrentVM()
7+
const vm = getCurrentInstance()
88
if (__DEV__ && !vm) {
99
warn(
1010
`${hook} is called when there is no active component instance to be ` +

src/index.ts

+4-6
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import Vue, { VueConstructor } from 'vue'
2-
import { Data, SetupFunction, SetupContext } from './component'
2+
import { Data, SetupFunction } from './component'
33
import { currentVue } from './runtimeContext'
44
import { install } from './install'
55
import { mixin } from './setup'
@@ -21,17 +21,15 @@ if (currentVue && typeof window !== 'undefined' && window.Vue) {
2121
}
2222

2323
export default plugin
24-
export { default as createElement } from './createElement'
25-
export { SetupContext }
24+
export { createElement as h } from './createElement'
25+
export { getCurrentInstance } from './runtimeContext'
2626
export {
2727
defineComponent,
2828
ComponentRenderProxy,
2929
PropType,
3030
PropOptions,
31+
SetupContext,
3132
} from './component'
32-
// For getting a hold of the interal instance in setup() - useful for advanced
33-
// plugins
34-
export { getCurrentVM as getCurrentInstance } from './runtimeContext'
3533

3634
export * from './apis/state'
3735
export * from './apis/lifecycle'

src/runtimeContext.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ export function setCurrentVue(vue: VueConstructor) {
1717
currentVue = vue
1818
}
1919

20-
export function getCurrentVM(): ComponentInstance | null {
20+
export function getCurrentInstance(): ComponentInstance | null {
2121
return currentVM
2222
}
2323

src/setup.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ import {
66
Data,
77
} from './component'
88
import { Ref, isRef, isReactive, markRaw } from './reactivity'
9-
import { getCurrentVM, setCurrentVM } from './runtimeContext'
9+
import { getCurrentInstance, setCurrentVM } from './runtimeContext'
1010
import { resolveSlots, createSlotProxy } from './helper'
1111
import { hasOwn, isPlainObject, assert, proxy, warn, isFunction } from './utils'
1212
import { ref } from './apis/state'
@@ -112,7 +112,7 @@ function activateCurrentInstance(
112112
fn: (vm_: ComponentInstance) => any,
113113
onError?: (err: Error) => void
114114
) {
115-
let preVm = getCurrentVM()
115+
let preVm = getCurrentInstance()
116116
setCurrentVM(vm)
117117
try {
118118
return fn(vm)

test/setup.spec.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ const Vue = require('vue/dist/vue.common.js')
22
const {
33
ref,
44
computed,
5-
createElement: h,
5+
h,
66
provide,
77
inject,
88
reactive,

test/setupContext.spec.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
const Vue = require('vue/dist/vue.common.js')
2-
const { ref, watch, createElement: h } = require('../src')
2+
const { h } = require('../src')
33

44
describe('setupContext', () => {
55
it('should have proper properties', () => {

test/templateRefs.spec.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
const Vue = require('vue/dist/vue.common.js')
2-
const { ref, watchEffect, watch, createElement: h } = require('../src')
2+
const { ref, watchEffect } = require('../src')
33

44
describe('ref', () => {
55
it('should work', (done) => {

test/types/defineComponent.spec.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import {
22
defineComponent,
3-
createElement as h,
3+
h,
44
ref,
55
SetupContext,
66
PropType,

test/v3/runtime-core/apiLifecycle.spec.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ import {
44
onBeforeMount,
55
onMounted,
66
ref,
7-
createElement as h,
7+
h,
88
onBeforeUpdate,
99
onUpdated,
1010
onBeforeUnmount,

0 commit comments

Comments
 (0)