component.js 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119
  1. import type { Config } from '../src/core/config'
  2. import type VNode from '../src/core/vdom/vnode'
  3. import type Watcher from '../src/core/observer/watcher'
  4. declare type Refs = {
  5. [key: string]: Component | Element | Array<Component | Element> | void;
  6. };
  7. declare interface Component {
  8. // constructor information
  9. static cid: number;
  10. static options: Object;
  11. // extend
  12. static extend: (options: Object) => Function;
  13. static superOptions: Object;
  14. static extendOptions: Object;
  15. static super: Class<Component>;
  16. // assets
  17. static directive: (id: string, def?: Function | Object) => Function | Object | void;
  18. static component: (id: string, def?: Class<Component> | Object) => Class<Component>;
  19. static filter: (id: string, def?: Function) => Function | void;
  20. // public properties
  21. $el: any; // so that we can attach __vue__ to it
  22. $data: Object;
  23. $options: ComponentOptions;
  24. $parent: Component | void;
  25. $root: Component;
  26. $children: Array<Component>;
  27. $refs: Refs;
  28. $slots: { [key: string]: Array<VNode> };
  29. $scopedSlots: { [key: string]: () => VNodeChildren };
  30. $vnode: VNode;
  31. $isServer: boolean;
  32. $props: Object;
  33. // public methods
  34. $mount: (el?: Element | string, hydrating?: boolean) => Component;
  35. $forceUpdate: () => void;
  36. $destroy: () => void;
  37. $set: (obj: Array<mixed> | Object, key: mixed, val: mixed) => void;
  38. $delete: (obj: Object, key: string) => void;
  39. $watch: (expOrFn: string | Function, cb: Function, options?: Object) => Function;
  40. $on: (event: string, fn: Function) => Component;
  41. $once: (event: string, fn: Function) => Component;
  42. $off: (event?: string, fn?: Function) => Component;
  43. $emit: (event: string, ...args: Array<mixed>) => Component;
  44. $nextTick: (fn: Function) => void;
  45. $createElement: (tag?: string | Component, data?: Object, children?: VNodeChildren) => VNode;
  46. // private properties
  47. _uid: number;
  48. _isVue: true;
  49. _self: Component;
  50. _renderProxy: Component;
  51. _renderContext: ?Component;
  52. _watcher: Watcher;
  53. _watchers: Array<Watcher>;
  54. _computedWatchers: { [key: string]: Watcher };
  55. _data: Object;
  56. _props: Object;
  57. _events: Object;
  58. _inactive: boolean;
  59. _isMounted: boolean;
  60. _isDestroyed: boolean;
  61. _isBeingDestroyed: boolean;
  62. _vnode: ?VNode;
  63. _staticTrees: ?Array<VNode>;
  64. _hasHookEvent: boolean;
  65. // private methods
  66. // lifecycle
  67. _init: Function;
  68. _mount: (el?: Element | void, hydrating?: boolean) => Component;
  69. _update: (vnode: VNode, hydrating?: boolean) => void;
  70. _updateFromParent: (
  71. propsData: ?Object,
  72. listeners: ?{ [key: string]: Function | Array<Function> },
  73. parentVnode: VNode,
  74. renderChildren: ?Array<VNode>
  75. ) => void;
  76. // rendering
  77. _render: () => VNode;
  78. __patch__: (a: Element | VNode | void, b: VNode) => any;
  79. // createElement
  80. // _c is internal that accepts `normalizationType` optimization hint
  81. _c: (vnode?: VNode, data?: VNodeData, children?: VNodeChildren, normalizationType?: number) => VNode | void;
  82. // renderStatic
  83. _m: (index: number, isInFor?: boolean) => VNode | VNodeChildren;
  84. // markOnce
  85. _o: (vnode: VNode | Array<VNode>, index: number, key: string) => VNode | VNodeChildren;
  86. // toString
  87. _s: (value: mixed) => string;
  88. // text to VNode
  89. _v: (value: string | number) => VNode;
  90. // toNumber
  91. _n: (value: string) => number | string;
  92. // empty vnode
  93. _e: () => VNode;
  94. // loose equal
  95. _q: (a: mixed, b: mixed) => boolean;
  96. // loose indexOf
  97. _i: (arr: Array<mixed>, val: mixed) => number;
  98. // resolveFilter
  99. _f: (id: string) => Function;
  100. // renderList
  101. _l: (val: mixed, render: Function) => ?Array<VNode>;
  102. // renderSlot
  103. _t: (name: string, fallback: ?Array<VNode>, props: ?Object) => ?Array<VNode>;
  104. // apply v-bind object
  105. _b: (data: any, value: any, asProp?: boolean) => VNodeData;
  106. // check custom keyCode
  107. _k: (eventKeyCode: number, key: string, builtInAlias: number | Array<number> | void) => boolean;
  108. // resolve scoped slots
  109. _u: (scopedSlots: Array<[string, Function]>) => { [key: string]: Function };
  110. // allow dynamic method registration
  111. [key: string]: any
  112. }