Преглед изворни кода

update types for new features

Evan You пре 9 година
родитељ
комит
73c5614740
6 измењених фајлова са 41 додато и 10 уклоњено
  1. 1 0
      flow/component.js
  2. 20 6
      flow/options.js
  3. 1 1
      src/core/config.js
  4. 7 2
      src/core/instance/inject.js
  5. 8 0
      types/options.d.ts
  6. 4 1
      types/vue.d.ts

+ 1 - 0
flow/component.js

@@ -69,6 +69,7 @@ declare interface Component {
   _vnode: ?VNode;
   _vnode: ?VNode;
   _staticTrees: ?Array<VNode>;
   _staticTrees: ?Array<VNode>;
   _hasHookEvent: boolean;
   _hasHookEvent: boolean;
+  _provided: ?Object;
 
 
   // private methods
   // private methods
   // lifecycle
   // lifecycle

+ 20 - 6
flow/options.js

@@ -24,18 +24,16 @@ declare type ComponentOptions = {
       cache?: boolean
       cache?: boolean
     }
     }
   };
   };
-  methods?: {
-    [key: string]: Function
-  };
-  watch?: {
-    [key: string]: Function | string
-  };
+  methods?: { [key: string]: Function };
+  watch?: { [key: string]: Function | string };
+
   // DOM
   // DOM
   el?: string | Element;
   el?: string | Element;
   template?: string;
   template?: string;
   render: (h: () => VNode) => VNode;
   render: (h: () => VNode) => VNode;
   renderError?: (h: () => VNode, err: Error) => VNode;
   renderError?: (h: () => VNode, err: Error) => VNode;
   staticRenderFns?: Array<() => VNode>;
   staticRenderFns?: Array<() => VNode>;
+
   // lifecycle
   // lifecycle
   beforeCreate?: Function;
   beforeCreate?: Function;
   created?: Function;
   created?: Function;
@@ -43,11 +41,27 @@ declare type ComponentOptions = {
   mounted?: Function;
   mounted?: Function;
   beforeUpdate?: Function;
   beforeUpdate?: Function;
   updated?: Function;
   updated?: Function;
+  activated?: Function;
+  deactivated?: Function;
+  beforeDestroy?: Function;
+  destroyed?: Function;
+
   // assets
   // assets
   directives?: { [key: string]: Object };
   directives?: { [key: string]: Object };
   components?: { [key: string]: Class<Component> };
   components?: { [key: string]: Class<Component> };
   transitions?: { [key: string]: Object };
   transitions?: { [key: string]: Object };
   filters?: { [key: string]: Function };
   filters?: { [key: string]: Function };
+
+  // context
+  provide?: Object | () => Object;
+  inject?: { [key: string]: string } | Array<string>;
+
+  // component v-model customization
+  model?: {
+    prop?: string;
+    event?: string;
+  };
+
   // misc
   // misc
   parent?: Component;
   parent?: Component;
   mixins?: Array<Object>;
   mixins?: Array<Object>;

+ 1 - 1
src/core/config.js

@@ -9,7 +9,7 @@ export type Config = {
   productionTip: boolean;
   productionTip: boolean;
   performance: boolean;
   performance: boolean;
   devtools: boolean;
   devtools: boolean;
-  errorHandler: ?Function;
+  errorHandler: ?(err: Error, vm: Component, info: string) => void;
   ignoredElements: Array<string>;
   ignoredElements: Array<string>;
   keyCodes: { [key: string]: number };
   keyCodes: { [key: string]: number };
   // platform
   // platform

+ 7 - 2
src/core/instance/inject.js

@@ -1,11 +1,16 @@
-export function initInjections (vm) {
-  const { provide, inject } = vm.$options
+/* @flow */
+
+export function initInjections (vm: Component) {
+  const provide = vm.$options.provide
+  const inject: any = vm.$options.inject
   if (provide) {
   if (provide) {
     vm._provided = typeof provide === 'function'
     vm._provided = typeof provide === 'function'
       ? provide.call(vm)
       ? provide.call(vm)
       : provide
       : provide
   }
   }
   if (inject) {
   if (inject) {
+    // inject is :any because flow is not smart enough to figure out cached
+    // isArray here
     const isArray = Array.isArray(inject)
     const isArray = Array.isArray(inject)
     const keys = isArray ? inject : Object.keys(inject)
     const keys = isArray ? inject : Object.keys(inject)
     for (let i = 0; i < keys.length; i++) {
     for (let i = 0; i < keys.length; i++) {

+ 8 - 0
types/options.d.ts

@@ -40,6 +40,14 @@ export interface ComponentOptions<V extends Vue> {
   transitions?: { [key: string]: Object };
   transitions?: { [key: string]: Object };
   filters?: { [key: string]: Function };
   filters?: { [key: string]: Function };
 
 
+  provide?: Object | (() => Object);
+  inject?: { [key: string]: string } | Array<string>;
+
+  model?: {
+    prop?: string;
+    event?: string;
+  };
+
   parent?: Vue;
   parent?: Vue;
   mixins?: (ComponentOptions<Vue> | typeof Vue)[];
   mixins?: (ComponentOptions<Vue> | typeof Vue)[];
   name?: string;
   name?: string;

+ 4 - 1
types/vue.d.ts

@@ -71,7 +71,10 @@ export declare class Vue {
     silent: boolean;
     silent: boolean;
     optionMergeStrategies: any;
     optionMergeStrategies: any;
     devtools: boolean;
     devtools: boolean;
-    errorHandler(err: Error, vm: Vue): void;
+    productionTip: boolean;
+    performance: boolean;
+    errorHandler(err: Error, vm: Vue, info: string): void;
+    ignoredElements: string[];
     keyCodes: { [key: string]: number };
     keyCodes: { [key: string]: number };
   }
   }