From 90b9884eb4a4103e18f75ce34f606b03114c02ec Mon Sep 17 00:00:00 2001 From: Evan You Date: Sat, 2 Nov 2019 12:18:35 -0400 Subject: [PATCH] refactor: rename/re-organize files --- .../KeepAlive.spec.ts} | 6 +++--- packages/runtime-core/src/apiApp.ts | 2 +- packages/runtime-core/src/apiLifecycle.ts | 2 +- packages/runtime-core/src/apiWatch.ts | 2 +- packages/runtime-core/src/component.ts | 2 +- .../{keepAlive.ts => components/KeepAlive.ts} | 16 ++++++++-------- packages/runtime-core/src/index.ts | 19 ++++++++++--------- .../src/{createRenderer.ts => renderer.ts} | 8 ++++---- .../src/{suspense.ts => rendererSuspense.ts} | 4 ++-- packages/runtime-core/src/vnode.ts | 6 +++--- .../{transition-group.ts => Transition.ts} | 0 .../{transition.ts => TransitionGroup.ts} | 0 12 files changed, 34 insertions(+), 33 deletions(-) rename packages/runtime-core/__tests__/{keepAlive.spec.ts => components/KeepAlive.spec.ts} (99%) rename packages/runtime-core/src/{keepAlive.ts => components/KeepAlive.ts} (95%) rename packages/runtime-core/src/{createRenderer.ts => renderer.ts} (99%) rename packages/runtime-core/src/{suspense.ts => rendererSuspense.ts} (99%) rename packages/runtime-dom/src/components/{transition-group.ts => Transition.ts} (100%) rename packages/runtime-dom/src/components/{transition.ts => TransitionGroup.ts} (100%) diff --git a/packages/runtime-core/__tests__/keepAlive.spec.ts b/packages/runtime-core/__tests__/components/KeepAlive.spec.ts similarity index 99% rename from packages/runtime-core/__tests__/keepAlive.spec.ts rename to packages/runtime-core/__tests__/components/KeepAlive.spec.ts index d7af1b33..ef15b7f4 100644 --- a/packages/runtime-core/__tests__/keepAlive.spec.ts +++ b/packages/runtime-core/__tests__/components/KeepAlive.spec.ts @@ -1,4 +1,3 @@ -import { ComponentOptions } from '../src/component' import { h, TestElement, @@ -7,9 +6,10 @@ import { ref, KeepAlive, serializeInner, - nextTick + nextTick, + ComponentOptions } from '@vue/runtime-test' -import { KeepAliveProps } from '../src/keepAlive' +import { KeepAliveProps } from '../../src/components/KeepAlive' describe('keep-alive', () => { let one: ComponentOptions diff --git a/packages/runtime-core/src/apiApp.ts b/packages/runtime-core/src/apiApp.ts index 20c65213..e431945c 100644 --- a/packages/runtime-core/src/apiApp.ts +++ b/packages/runtime-core/src/apiApp.ts @@ -2,7 +2,7 @@ import { Component, Data, validateComponentName } from './component' import { ComponentOptions } from './apiOptions' import { ComponentPublicInstance } from './componentProxy' import { Directive, validateDirectiveName } from './directives' -import { RootRenderFunction } from './createRenderer' +import { RootRenderFunction } from './renderer' import { InjectionKey } from './apiInject' import { isFunction, NO } from '@vue/shared' import { warn } from './warning' diff --git a/packages/runtime-core/src/apiLifecycle.ts b/packages/runtime-core/src/apiLifecycle.ts index 18de3e2c..1bab9ca9 100644 --- a/packages/runtime-core/src/apiLifecycle.ts +++ b/packages/runtime-core/src/apiLifecycle.ts @@ -10,7 +10,7 @@ import { warn } from './warning' import { capitalize } from '@vue/shared' import { pauseTracking, resumeTracking, DebuggerEvent } from '@vue/reactivity' -export { onActivated, onDeactivated } from './keepAlive' +export { onActivated, onDeactivated } from './components/KeepAlive' export function injectHook( type: LifecycleHooks, diff --git a/packages/runtime-core/src/apiWatch.ts b/packages/runtime-core/src/apiWatch.ts index 8abe22ee..2673b8dc 100644 --- a/packages/runtime-core/src/apiWatch.ts +++ b/packages/runtime-core/src/apiWatch.ts @@ -27,7 +27,7 @@ import { callWithAsyncErrorHandling } from './errorHandling' import { onBeforeUnmount } from './apiLifecycle' -import { queuePostRenderEffect } from './createRenderer' +import { queuePostRenderEffect } from './renderer' export type WatchHandler = ( value: T, diff --git a/packages/runtime-core/src/component.ts b/packages/runtime-core/src/component.ts index ea554144..621f95bc 100644 --- a/packages/runtime-core/src/component.ts +++ b/packages/runtime-core/src/component.ts @@ -25,7 +25,7 @@ import { makeMap, isPromise } from '@vue/shared' -import { SuspenseBoundary } from './suspense' +import { SuspenseBoundary } from './rendererSuspense' import { CompilerError, CompilerOptions, diff --git a/packages/runtime-core/src/keepAlive.ts b/packages/runtime-core/src/components/KeepAlive.ts similarity index 95% rename from packages/runtime-core/src/keepAlive.ts rename to packages/runtime-core/src/components/KeepAlive.ts index 27b20a4c..6b4618fd 100644 --- a/packages/runtime-core/src/keepAlive.ts +++ b/packages/runtime-core/src/components/KeepAlive.ts @@ -6,19 +6,19 @@ import { ComponentInternalInstance, LifecycleHooks, currentInstance -} from './component' -import { VNode, cloneVNode, isVNode } from './vnode' -import { warn } from './warning' -import { onBeforeUnmount, injectHook, onUnmounted } from './apiLifecycle' +} from '../component' +import { VNode, cloneVNode, isVNode } from '../vnode' +import { warn } from '../warning' +import { onBeforeUnmount, injectHook, onUnmounted } from '../apiLifecycle' import { isString, isArray } from '@vue/shared' -import { watch } from './apiWatch' -import { ShapeFlags } from './shapeFlags' -import { SuspenseBoundary } from './suspense' +import { watch } from '../apiWatch' +import { ShapeFlags } from '../shapeFlags' +import { SuspenseBoundary } from '../rendererSuspense' import { RendererInternals, queuePostRenderEffect, invokeHooks -} from './createRenderer' +} from '../renderer' type MatchPattern = string | RegExp | string[] | RegExp[] diff --git a/packages/runtime-core/src/index.ts b/packages/runtime-core/src/index.ts index c51b1f26..e09d17e7 100644 --- a/packages/runtime-core/src/index.ts +++ b/packages/runtime-core/src/index.ts @@ -1,14 +1,18 @@ // Public API ------------------------------------------------------------------ -export { createComponent } from './apiCreateComponent' -export { nextTick } from './scheduler' export * from './apiReactivity' export * from './apiWatch' export * from './apiLifecycle' export * from './apiInject' +export { nextTick } from './scheduler' +export { createComponent } from './apiCreateComponent' // Advanced API ---------------------------------------------------------------- +// For getting a hold of the internal instance in setup() - useful for advanced +// plugins +export { getCurrentInstance } from './component' + // For raw render function users export { h } from './h' export { @@ -21,7 +25,7 @@ export { // VNode type symbols export { Text, Comment, Fragment, Portal, Suspense } from './vnode' // Internal Components -export { KeepAlive } from './keepAlive' +export { KeepAlive } from './components/KeepAlive' // VNode flags export { PublicShapeFlags as ShapeFlags } from './shapeFlags' import { PublicPatchFlags } from '@vue/shared' @@ -40,11 +44,8 @@ export const PatchFlags = PublicPatchFlags as { BAIL: number } -// For advanced plugins -export { getCurrentInstance } from './component' - // For custom renderers -export { createRenderer, RootRenderFunction } from './createRenderer' +export { createRenderer, RootRenderFunction } from './renderer' export { warn } from './warning' export { handleError, @@ -94,7 +95,7 @@ export { } from './apiOptions' export { ComponentPublicInstance } from './componentProxy' -export { RendererOptions } from './createRenderer' +export { RendererOptions } from './renderer' export { Slot, Slots } from './componentSlots' export { Prop, @@ -110,6 +111,6 @@ export { FunctionDirective, DirectiveArguments } from './directives' -export { SuspenseBoundary } from './suspense' +export { SuspenseBoundary } from './rendererSuspense' export const version = __VERSION__ diff --git a/packages/runtime-core/src/createRenderer.ts b/packages/runtime-core/src/renderer.ts similarity index 99% rename from packages/runtime-core/src/createRenderer.ts rename to packages/runtime-core/src/renderer.ts index 7cd7f23d..2d6d5d5a 100644 --- a/packages/runtime-core/src/createRenderer.ts +++ b/packages/runtime-core/src/renderer.ts @@ -47,11 +47,11 @@ import { ComponentPublicInstance } from './componentProxy' import { App, createAppAPI } from './apiApp' import { SuspenseBoundary, - SuspenseImpl, + Suspense, queueEffectWithSuspense -} from './suspense' +} from './rendererSuspense' import { ErrorCodes, callWithErrorHandling } from './errorHandling' -import { KeepAliveSink } from './keepAlive' +import { KeepAliveSink } from './components/KeepAlive' export interface RendererOptions { patchProp( @@ -265,7 +265,7 @@ export function createRenderer< optimized ) } else if (__FEATURE_SUSPENSE__ && shapeFlag & ShapeFlags.SUSPENSE) { - ;(type as typeof SuspenseImpl).process( + ;(type as typeof Suspense).process( n1, n2, container, diff --git a/packages/runtime-core/src/suspense.ts b/packages/runtime-core/src/rendererSuspense.ts similarity index 99% rename from packages/runtime-core/src/suspense.ts rename to packages/runtime-core/src/rendererSuspense.ts index 1494d241..ab39a5ea 100644 --- a/packages/runtime-core/src/suspense.ts +++ b/packages/runtime-core/src/rendererSuspense.ts @@ -3,13 +3,13 @@ import { ShapeFlags } from './shapeFlags' import { isFunction, isArray } from '@vue/shared' import { ComponentInternalInstance, handleSetupResult } from './component' import { Slots } from './componentSlots' -import { RendererInternals } from './createRenderer' +import { RendererInternals } from './renderer' import { queuePostFlushCb, queueJob } from './scheduler' import { updateHOCHostEl } from './componentRenderUtils' import { handleError, ErrorCodes } from './errorHandling' import { pushWarningContext, popWarningContext } from './warning' -export const SuspenseImpl = { +export const Suspense = { __isSuspense: true, process( n1: VNode | null, diff --git a/packages/runtime-core/src/vnode.ts b/packages/runtime-core/src/vnode.ts index 1f6d9040..1eecd030 100644 --- a/packages/runtime-core/src/vnode.ts +++ b/packages/runtime-core/src/vnode.ts @@ -16,9 +16,9 @@ import { RawSlots } from './componentSlots' import { ShapeFlags } from './shapeFlags' import { isReactive, Ref } from '@vue/reactivity' import { AppContext } from './apiApp' -import { SuspenseBoundary } from './suspense' +import { SuspenseBoundary } from './rendererSuspense' import { DirectiveBinding } from './directives' -import { SuspenseImpl } from './suspense' +import { Suspense as SuspenseImpl } from './rendererSuspense' export const Fragment = (Symbol(__DEV__ ? 'Fragment' : undefined) as any) as { // type differentiator for h() @@ -48,7 +48,7 @@ export type VNodeTypes = | typeof Portal | typeof Text | typeof Comment - | typeof SuspenseImpl + | typeof Suspense export interface VNodeProps { [key: string]: any diff --git a/packages/runtime-dom/src/components/transition-group.ts b/packages/runtime-dom/src/components/Transition.ts similarity index 100% rename from packages/runtime-dom/src/components/transition-group.ts rename to packages/runtime-dom/src/components/Transition.ts diff --git a/packages/runtime-dom/src/components/transition.ts b/packages/runtime-dom/src/components/TransitionGroup.ts similarity index 100% rename from packages/runtime-dom/src/components/transition.ts rename to packages/runtime-dom/src/components/TransitionGroup.ts