Skip to content

Commit

Permalink
wip: rename dir to v3
Browse files Browse the repository at this point in the history
  • Loading branch information
yyx990803 committed May 27, 2022
1 parent 9321458 commit 1f1046b
Show file tree
Hide file tree
Showing 30 changed files with 1,214 additions and 49 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@
"test:e2e": "npm run build -- web-full-prod,web-server-renderer-basic && vitest run test/e2e",
"test:transition": "karma start test/transition/karma.conf.js",
"test:types": "tsc -p ./types/tsconfig.json",
"format": "prettier --write --parser typescript \"(src|test|packages)/**/*.ts\"",
"format": "prettier --write --parser typescript \"(src|test|packages|types)/**/*.ts\"",
"ts-check": "tsc -p tsconfig.json --noEmit",
"ts-check:test": "tsc -p test/tsconfig.json --noEmit",
"bench:ssr": "npm run build:ssr && node benchmarks/ssr/renderToString.js && node benchmarks/ssr/renderToStream.js",
Expand Down
12 changes: 0 additions & 12 deletions src/composition-api/currentInstance.ts

This file was deleted.

2 changes: 1 addition & 1 deletion src/core/observer/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ import {
isServerRendering,
hasChanged
} from '../util/index'
import { isReadonly, isRef } from '../../composition-api'
import { isReadonly, isRef } from '../../v3'

const arrayKeys = Object.getOwnPropertyNames(arrayMethods)

Expand Down
3 changes: 2 additions & 1 deletion src/core/util/debug.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import config from '../config'
import { noop, isArray } from 'shared/util'
import type { Component } from 'typescript/component'
import { currentInstance } from 'v3/currentInstance'

export let warn = noop
export let tip = noop
Expand All @@ -13,7 +14,7 @@ if (__DEV__) {
const classify = str =>
str.replace(classifyRE, c => c.toUpperCase()).replace(/[-_]/g, '')

warn = (msg, vm) => {
warn = (msg, vm = currentInstance) => {
// TODO get current instance
const trace = vm ? generateComponentTrace(vm) : ''

Expand Down
2 changes: 1 addition & 1 deletion src/platforms/web/entry-runtime-esm.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,4 @@ import Vue from './runtime/index'

export default Vue

export * from 'vca/index'
export * from 'v3'
2 changes: 1 addition & 1 deletion src/platforms/web/entry-runtime-with-compiler-esm.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,4 @@ import Vue from './runtime-with-compiler'

export default Vue

export * from 'vca/index'
export * from 'v3'
4 changes: 2 additions & 2 deletions src/platforms/web/entry-runtime-with-compiler.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
import Vue from './runtime-with-compiler'
import * as vca from 'vca/index'
import * as vca from 'v3'
import { extend } from 'shared/util'

extend(Vue, vca)

import { effect } from 'vca/reactivity/effect'
import { effect } from 'v3/reactivity/effect'
Vue.effect = effect

export default Vue
2 changes: 1 addition & 1 deletion src/platforms/web/entry-runtime.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import Vue from './runtime/index'
import * as vca from 'vca/index'
import * as vca from 'v3'
import { extend } from 'shared/util'

extend(Vue, vca)
Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
21 changes: 21 additions & 0 deletions src/v3/currentInstance.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
import { Component } from 'typescript/component'

export let currentInstance: Component | null = null

/**
* This is exposed for compatibility with v3 (e.g. some functions in VueUse
* relies on it). Do not use this internally, just use `currentInstance`.
*
* @private this function needs manual type declaration because it relies
* on previously manually authored types from Vue 2
*/
export function getCurrentInstance(): { proxy: Component } | null {
return currentInstance && { proxy: currentInstance }
}

/**
* @private
*/
export function setCurrentInstance(vm: Component | null) {
currentInstance = vm
}
27 changes: 27 additions & 0 deletions src/v3/h.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
import { createElement } from '../core/vdom/create-element'
import VNode from 'core/vdom/vnode'
import { VNodeData, VNodeChildren } from 'typescript/vnode'
import { currentInstance } from './currentInstance'
import { warn } from 'core/util'

/**
* @private this function needs manual type declaration because it relies
* on previously manually authored types from Vue 2
*/
export function h(type: any, children?: VNodeChildren): VNode
export function h(
type: any,
props?: VNodeData | null,
children?: VNodeChildren
): VNode

export function h(type: any, props?: any, children?: any) {
if (!currentInstance) {
__DEV__ &&
warn(
`globally imported h() can only be invoked when there is an active ` +
`component instance, e.g. synchronously in a component's render or setup function.`
)
}
return createElement(currentInstance!, type, props, children, 2, true)
}
15 changes: 14 additions & 1 deletion src/composition-api/index.ts → src/v3/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -46,5 +46,18 @@ export {
watch,
watchEffect,
watchPostEffect,
watchSyncEffect
watchSyncEffect,
WatchEffect,
WatchOptions,
WatchOptionsBase,
WatchCallback,
WatchSource,
WatchStopHandle,
DebuggerOptions
} from './apiWatch'

export { DebuggerEvent } from './reactivity/effect'
export { TrackOpTypes, TriggerOpTypes } from './reactivity/operations'

export { h } from './h'
export { getCurrentInstance } from './currentInstance'
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
7 changes: 3 additions & 4 deletions test/tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -23,14 +23,13 @@
"paths": {
"compiler/*": ["../src/compiler/*"],
"core/*": ["../src/core/*"],

"server/*": ["../src/server/*"],
"sfc/*": ["../src/sfc/*"],
"shared/*": ["../src/shared/*"],

"web/*": ["../src/platforms/web/*"],
"vca/*": ["../src/composition-api/*"],

"v3": ["../src/v3/index"],
"v3/*": ["../src/v3/*"],
"typescript/*": ["../typescript/*"],
"vue": ["../src/platforms/web/entry-runtime-with-compiler"]
}
},
Expand Down
Loading

0 comments on commit 1f1046b

Please sign in to comment.