Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
chore: add subfolders to lint and lint
- Loading branch information
Showing
29 changed files
with
2,426 additions
and
2,293 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,59 +1,65 @@ | ||
import { ComponentInstance } from '../component'; | ||
import { currentVMInFn } from '../helper'; | ||
import { hasOwn, warn } from '../utils'; | ||
import { getCurrentVM } from '../runtimeContext'; | ||
import { ComponentInstance } from '../component' | ||
import { currentVMInFn } from '../helper' | ||
import { hasOwn, warn } from '../utils' | ||
import { getCurrentVM } from '../runtimeContext' | ||
|
||
const NOT_FOUND = {}; | ||
const NOT_FOUND = {} | ||
export interface InjectionKey<T> extends Symbol {} | ||
|
||
function resolveInject(provideKey: InjectionKey<any> | string, vm: ComponentInstance): any { | ||
let source = vm; | ||
function resolveInject( | ||
provideKey: InjectionKey<any> | string, | ||
vm: ComponentInstance | ||
): any { | ||
let source = vm | ||
while (source) { | ||
// @ts-ignore | ||
if (source._provided && hasOwn(source._provided, provideKey)) { | ||
//@ts-ignore | ||
return source._provided[provideKey]; | ||
return source._provided[provideKey] | ||
} | ||
source = source.$parent; | ||
source = source.$parent | ||
} | ||
|
||
return NOT_FOUND; | ||
return NOT_FOUND | ||
} | ||
|
||
export function provide<T>(key: InjectionKey<T> | string, value: T): void { | ||
const vm: any = currentVMInFn('provide'); | ||
if (!vm) return; | ||
const vm: any = currentVMInFn('provide') | ||
if (!vm) return | ||
|
||
if (!vm._provided) { | ||
const provideCache = {}; | ||
const provideCache = {} | ||
Object.defineProperty(vm, '_provided', { | ||
get: () => provideCache, | ||
set: (v) => Object.assign(provideCache, v), | ||
}); | ||
}) | ||
} | ||
|
||
vm._provided[key as string] = value; | ||
vm._provided[key as string] = value | ||
} | ||
|
||
export function inject<T>(key: InjectionKey<T> | string): T | undefined; | ||
export function inject<T>(key: InjectionKey<T> | string, defaultValue: T): T; | ||
export function inject(key: InjectionKey<any> | string, defaultValue?: unknown) { | ||
export function inject<T>(key: InjectionKey<T> | string): T | undefined | ||
export function inject<T>(key: InjectionKey<T> | string, defaultValue: T): T | ||
export function inject( | ||
key: InjectionKey<any> | string, | ||
defaultValue?: unknown | ||
) { | ||
if (!key) { | ||
return defaultValue; | ||
return defaultValue | ||
} | ||
|
||
const vm = getCurrentVM(); | ||
const vm = getCurrentVM() | ||
if (vm) { | ||
const val = resolveInject(key, vm); | ||
const val = resolveInject(key, vm) | ||
if (val !== NOT_FOUND) { | ||
return val; | ||
return val | ||
} else { | ||
if (defaultValue === undefined && process.env.NODE_ENV !== 'production') { | ||
warn(`Injection "${String(key)}" not found`, vm); | ||
warn(`Injection "${String(key)}" not found`, vm) | ||
} | ||
return defaultValue; | ||
return defaultValue | ||
} | ||
} else { | ||
warn(`inject() can only be used inside setup() or functional components.`); | ||
warn(`inject() can only be used inside setup() or functional components.`) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,44 +1,49 @@ | ||
import { VueConstructor } from 'vue'; | ||
import { ComponentInstance } from '../component'; | ||
import { getCurrentVue, setCurrentVM, getCurrentVM } from '../runtimeContext'; | ||
import { currentVMInFn } from '../helper'; | ||
import { VueConstructor } from 'vue' | ||
import { ComponentInstance } from '../component' | ||
import { getCurrentVue, setCurrentVM, getCurrentVM } from '../runtimeContext' | ||
import { currentVMInFn } from '../helper' | ||
|
||
const genName = (name: string) => `on${name[0].toUpperCase() + name.slice(1)}`; | ||
const genName = (name: string) => `on${name[0].toUpperCase() + name.slice(1)}` | ||
function createLifeCycle(lifeCyclehook: string) { | ||
return (callback: Function) => { | ||
const vm = currentVMInFn(genName(lifeCyclehook)); | ||
const vm = currentVMInFn(genName(lifeCyclehook)) | ||
if (vm) { | ||
injectHookOption(getCurrentVue(), vm, lifeCyclehook, callback); | ||
injectHookOption(getCurrentVue(), vm, lifeCyclehook, callback) | ||
} | ||
}; | ||
} | ||
} | ||
|
||
function injectHookOption(Vue: VueConstructor, vm: ComponentInstance, hook: string, val: Function) { | ||
const options = vm.$options as any; | ||
const mergeFn = Vue.config.optionMergeStrategies[hook]; | ||
options[hook] = mergeFn(options[hook], wrapHookCall(vm, val)); | ||
function injectHookOption( | ||
Vue: VueConstructor, | ||
vm: ComponentInstance, | ||
hook: string, | ||
val: Function | ||
) { | ||
const options = vm.$options as any | ||
const mergeFn = Vue.config.optionMergeStrategies[hook] | ||
options[hook] = mergeFn(options[hook], wrapHookCall(vm, val)) | ||
} | ||
|
||
function wrapHookCall(vm: ComponentInstance, fn: Function) { | ||
return (...args: any) => { | ||
let preVm = getCurrentVM(); | ||
setCurrentVM(vm); | ||
let preVm = getCurrentVM() | ||
setCurrentVM(vm) | ||
try { | ||
return fn(...args); | ||
return fn(...args) | ||
} finally { | ||
setCurrentVM(preVm); | ||
setCurrentVM(preVm) | ||
} | ||
}; | ||
} | ||
} | ||
|
||
// export const onCreated = createLifeCycle('created'); | ||
export const onBeforeMount = createLifeCycle('beforeMount'); | ||
export const onMounted = createLifeCycle('mounted'); | ||
export const onBeforeUpdate = createLifeCycle('beforeUpdate'); | ||
export const onUpdated = createLifeCycle('updated'); | ||
export const onBeforeUnmount = createLifeCycle('beforeDestroy'); | ||
export const onUnmounted = createLifeCycle('destroyed'); | ||
export const onErrorCaptured = createLifeCycle('errorCaptured'); | ||
export const onActivated = createLifeCycle('activated'); | ||
export const onDeactivated = createLifeCycle('deactivated'); | ||
export const onServerPrefetch = createLifeCycle('serverPrefetch'); | ||
export const onBeforeMount = createLifeCycle('beforeMount') | ||
export const onMounted = createLifeCycle('mounted') | ||
export const onBeforeUpdate = createLifeCycle('beforeUpdate') | ||
export const onUpdated = createLifeCycle('updated') | ||
export const onBeforeUnmount = createLifeCycle('beforeDestroy') | ||
export const onUnmounted = createLifeCycle('destroyed') | ||
export const onErrorCaptured = createLifeCycle('errorCaptured') | ||
export const onActivated = createLifeCycle('activated') | ||
export const onDeactivated = createLifeCycle('deactivated') | ||
export const onServerPrefetch = createLifeCycle('serverPrefetch') |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -14,4 +14,4 @@ export { | |
toRaw, | ||
shallowRef, | ||
triggerRef, | ||
} from '../reactivity'; | ||
} from '../reactivity' |
Oops, something went wrong.