]> git.ipfire.org Git - thirdparty/vuejs/core.git/commitdiff
wip: update runtime core to updated reactivity api names
authorEvan You <yyx990803@gmail.com>
Fri, 16 Aug 2019 14:02:53 +0000 (10:02 -0400)
committerEvan You <yyx990803@gmail.com>
Fri, 16 Aug 2019 14:02:53 +0000 (10:02 -0400)
packages/runtime-core/src/apiInject.ts
packages/runtime-core/src/apiState.ts
packages/runtime-core/src/apiWatch.ts
packages/runtime-core/src/component.ts
packages/runtime-core/src/componentProps.ts

index f3133fb5a908b3376a41e0bf2b1902ada008937a..602fc1c0cfe9955dc66cbb0065db97503b7c7c5e 100644 (file)
@@ -1,9 +1,9 @@
-import { value, isValue, Value } from './apiState'
+import { ref, isRef, Ref } from './apiState'
 import { currentInstance } from './component'
 
-export interface Key<T> extends Symbol {}
+export interface InjectionKey<T> extends Symbol {}
 
-export function provide<T>(key: Key<T> | string, value: T | Value<T>) {
+export function provide<T>(key: InjectionKey<T> | string, value: T | Ref<T>) {
   if (!currentInstance) {
     // TODO warn
   } else {
@@ -22,15 +22,19 @@ export function provide<T>(key: Key<T> | string, value: T | Value<T>) {
   }
 }
 
-export function inject<T>(key: Key<T> | string): Value<T> | undefined {
+export function inject<T>(key: InjectionKey<T> | string): Ref<T> | undefined
+export function inject<T>(
+  key: InjectionKey<T> | string,
+  defaultValue: T
+): Ref<T>
+export function inject(key: InjectionKey<any> | string, defaultValue?: any) {
   if (!currentInstance) {
     // TODO warn
   } else {
     // TODO should also check for app-level provides
     const provides = currentInstance.parent && currentInstance.provides
-    if (provides) {
-      const val = provides[key as any] as any
-      return isValue(val) ? val : value(val)
-    }
+    const val =
+      provides && key in provides ? (provides[key as any] as any) : defaultValue
+    return isRef(val) ? val : ref(val)
   }
 }
index b66199f26f9b691e54986f7629327476da4c4541..a40df59c165a16658ad613b693acdbea299a08a0 100644 (file)
@@ -1,10 +1,10 @@
 export {
-  value,
-  isValue,
-  state,
-  isState,
-  immutableState,
-  isImmutableState,
+  ref,
+  isRef,
+  reactive,
+  isReactive,
+  immutable,
+  isImmutable,
   toRaw,
   markImmutable,
   markNonReactive,
@@ -14,14 +14,14 @@ export {
   ReactiveEffectOptions,
   DebuggerEvent,
   OperationTypes,
-  Value,
-  ComputedValue,
-  UnwrapValue
+  Ref,
+  ComputedRef,
+  UnwrapRef
 } from '@vue/reactivity'
 
 import {
   computed as _computed,
-  ComputedValue,
+  ComputedRef,
   ReactiveEffect
 } from '@vue/reactivity'
 
@@ -39,7 +39,7 @@ export function recordEffect(effect: ReactiveEffect) {
 export function computed<T, C = null>(
   getter: () => T,
   setter?: (v: T) => void
-): ComputedValue<T> {
+): ComputedRef<T> {
   const c = _computed(getter, setter)
   recordEffect(c.effect)
   return c
index 85e33e759f781bfa0802059ce1f39ef2332db686..a92596f475c2994fffc614e5f9fb6aed21a4fee8 100644 (file)
@@ -1,8 +1,8 @@
 import {
   effect,
   stop,
-  isValue,
-  Value,
+  isRef,
+  Ref,
   ReactiveEffectOptions
 } from '@vue/reactivity'
 import { queueJob, queuePostFlushCb } from './scheduler'
@@ -17,7 +17,7 @@ export interface WatchOptions {
   onTrigger?: ReactiveEffectOptions['onTrigger']
 }
 
-type WatcherSource<T> = Value<T> | (() => T)
+type WatcherSource<T> = Ref<T> | (() => T)
 
 const invoke = (fn: Function) => fn()
 
@@ -34,8 +34,8 @@ export function watch<T>(
     flush === 'sync' ? invoke : flush === 'pre' ? queueJob : queuePostFlushCb
 
   const baseGetter = isArray(source)
-    ? () => source.map(s => (isValue(s) ? s.value : s()))
-    : isValue(source)
+    ? () => source.map(s => (isRef(s) ? s.value : s()))
+    : isRef(source)
       ? () => source.value
       : source
   const getter = deep ? () => traverse(baseGetter()) : baseGetter
index 8df68a691697c1c7a5149eb708f6859cf6ac7180..117f4b4760b7be67b53dd67e2c9ac550d3cfbdff 100644 (file)
@@ -1,10 +1,5 @@
 import { VNode, normalizeVNode, VNodeChild } from './vnode'
-import {
-  ReactiveEffect,
-  UnwrapValue,
-  state,
-  immutableState
-} from '@vue/reactivity'
+import { ReactiveEffect, UnwrapRef, reactive, immutable } from '@vue/reactivity'
 import { EMPTY_OBJ, isFunction, capitalize, invokeHandlers } from '@vue/shared'
 import { RenderProxyHandlers } from './componentProxy'
 import { ComponentPropsOptions, ExtractPropTypes } from './componentProps'
@@ -34,7 +29,7 @@ type SetupFunction<Props, RawBindings> = (
 ) => RawBindings | (() => VNodeChild)
 
 type RenderFunction<Props = {}, RawBindings = {}> = <
-  Bindings extends UnwrapValue<RawBindings>
+  Bindings extends UnwrapRef<RawBindings>
 >(
   this: ComponentRenderProxy<Props, Bindings>,
   ctx: ComponentRenderProxy<Props, Bindings>
@@ -135,7 +130,7 @@ export function createComponent<Props>(
 export function createComponent<Props, RawBindings>(
   options: ComponentOptionsWithoutProps<Props, RawBindings>
 ): {
-  new (): ComponentRenderProxy<Props, UnwrapValue<RawBindings>>
+  new (): ComponentRenderProxy<Props, UnwrapRef<RawBindings>>
 }
 // overload 3: object format with array props declaration
 // props inferred as { [key in PropNames]?: unknown }
@@ -145,7 +140,7 @@ export function createComponent<PropNames extends string, RawBindings>(
 ): {
   new (): ComponentRenderProxy<
     { [key in PropNames]?: unknown },
-    UnwrapValue<RawBindings>
+    UnwrapRef<RawBindings>
   >
 }
 // overload 4: object format with object props declaration
@@ -156,7 +151,7 @@ export function createComponent<PropsOptions, RawBindings>(
   // for Vetur and TSX support
   new (): ComponentRenderProxy<
     ExtractPropTypes<PropsOptions>,
-    UnwrapValue<RawBindings>,
+    UnwrapRef<RawBindings>,
     ExtractPropTypes<PropsOptions, false>
   >
 }
@@ -232,7 +227,7 @@ export function setupStatefulComponent(instance: ComponentInstance) {
     // so props change can be tracked by watchers
     // it will be updated in resolveProps() on updates before render
     const propsProxy = (instance.propsProxy = setup.length
-      ? immutableState(instance.props)
+      ? immutable(instance.props)
       : null)
     const setupContext = (instance.setupContext =
       setup.length > 1 ? createSetupContext(instance) : null)
@@ -247,7 +242,7 @@ export function setupStatefulComponent(instance: ComponentInstance) {
     } else {
       // setup returned bindings.
       // assuming a render function compiled from template is present.
-      instance.data = state(setupResult)
+      instance.data = reactive(setupResult)
       if (__DEV__ && !Component.render) {
         // TODO warn missing render fn
       }
index c7bf08043d871c500e3365b17d8f3b2e2a0fc3c3..cb8ebb2cbd6fd150ce1f91af373857aa721d2ad2 100644 (file)
@@ -1,4 +1,4 @@
-import { immutableState, toRaw, lock, unlock } from '@vue/reactivity'
+import { immutable, toRaw, lock, unlock } from '@vue/reactivity'
 import {
   EMPTY_OBJ,
   camelize,
@@ -179,10 +179,10 @@ export function resolveProps(
   // lock immutable
   lock()
 
-  instance.props = __DEV__ ? immutableState(props) : props
+  instance.props = __DEV__ ? immutable(props) : props
   instance.attrs = options
     ? __DEV__
-      ? immutableState(attrs)
+      ? immutable(attrs)
       : attrs
     : instance.props
 }