* Vuex init hook, injected into each instances init hooks list.
(this: ComponentInstance)
| 46 | */ |
| 47 | |
| 48 | function functionApiInit(this: ComponentInstance) { |
| 49 | const vm = this |
| 50 | const $options = vm.$options |
| 51 | const { setup, render } = $options |
| 52 | |
| 53 | if (render) { |
| 54 | // keep currentInstance accessible for createElement |
| 55 | $options.render = function (...args: any): any { |
| 56 | return activateCurrentInstance(toVue3ComponentInstance(vm), () => |
| 57 | render.apply(this, args) |
| 58 | ) |
| 59 | } |
| 60 | } |
| 61 | |
| 62 | if (!setup) { |
| 63 | return |
| 64 | } |
| 65 | if (!isFunction(setup)) { |
| 66 | if (__DEV__) { |
| 67 | warn( |
| 68 | 'The "setup" option should be a function that returns a object in component definitions.', |
| 69 | vm |
| 70 | ) |
| 71 | } |
| 72 | return |
| 73 | } |
| 74 | |
| 75 | const { data } = $options |
| 76 | // wrapper the data option, so we can invoke setup before data get resolved |
| 77 | $options.data = function wrappedData() { |
| 78 | initSetup(vm, vm.$props) |
| 79 | return isFunction(data) |
| 80 | ? ( |
| 81 | data as (this: ComponentInstance, x: ComponentInstance) => object |
| 82 | ).call(vm, vm) |
| 83 | : data || {} |
| 84 | } |
| 85 | } |
| 86 | |
| 87 | function initSetup(vm: ComponentInstance, props: Record<any, any> = {}) { |
| 88 | const setup = vm.$options.setup! |
nothing calls this directly
no test coverage detected
searching dependent graphs…