Skip to content

Commit 233dafa

Browse files
committed
chore: add subfolders to lint and lint
1 parent 5f72e26 commit 233dafa

29 files changed

+2426
-2293
lines changed

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@
2727
"scripts": {
2828
"start": "concurrently \"tsc --emitDeclarationOnly -w\" \"cross-env TARGET=es rollup -c -w\"",
2929
"build": "rimraf dist typings && tsc --emitDeclarationOnly && rollup -c",
30-
"lint": "prettier --write --parser typescript \"{src,test,test-dts}/*.ts?(x)\" && prettier --write \"{src,test}/*.js\"",
30+
"lint": "prettier --write --parser typescript \"{src,test,test-dts}/**/*.ts?(x)\" && prettier --write \"{src,test}/**/*.js\"",
3131
"test": "yarn test-dts && yarn test-unit",
3232
"test-unit": "cross-env NODE_ENV=test jest",
3333
"test-dts": "tsc -p ./test-dts/tsconfig.json && yarn build && tsc -p ./test-dts/tsconfig.build.json",

src/apis/computed.ts

Lines changed: 20 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1,34 +1,34 @@
1-
import { getCurrentVue, getCurrentVM } from '../runtimeContext';
2-
import { createRef, Ref } from '../reactivity';
3-
import { defineComponentInstance } from '../helper';
4-
import { warn } from '../utils';
1+
import { getCurrentVue, getCurrentVM } from '../runtimeContext'
2+
import { createRef, Ref } from '../reactivity'
3+
import { defineComponentInstance } from '../helper'
4+
import { warn } from '../utils'
55

66
interface Option<T> {
7-
get: () => T;
8-
set: (value: T) => void;
7+
get: () => T
8+
set: (value: T) => void
99
}
1010

1111
export interface ComputedRef<T = any> extends WritableComputedRef<T> {
12-
readonly value: T;
12+
readonly value: T
1313
}
1414

1515
export interface WritableComputedRef<T> extends Ref<T> {}
1616

1717
// read-only
18-
export function computed<T>(getter: Option<T>['get']): ComputedRef<T>;
18+
export function computed<T>(getter: Option<T>['get']): ComputedRef<T>
1919
// writable
20-
export function computed<T>(options: Option<T>): WritableComputedRef<T>;
20+
export function computed<T>(options: Option<T>): WritableComputedRef<T>
2121
// implement
2222
export function computed<T>(
2323
options: Option<T>['get'] | Option<T>
2424
): ComputedRef<T> | WritableComputedRef<T> {
25-
const vm = getCurrentVM();
26-
let get: Option<T>['get'], set: Option<T>['set'] | undefined;
25+
const vm = getCurrentVM()
26+
let get: Option<T>['get'], set: Option<T>['set'] | undefined
2727
if (typeof options === 'function') {
28-
get = options;
28+
get = options
2929
} else {
30-
get = options.get;
31-
set = options.set;
30+
get = options.get
31+
set = options.set
3232
}
3333

3434
const computedHost = defineComponentInstance(getCurrentVue(), {
@@ -38,19 +38,19 @@ export function computed<T>(
3838
set,
3939
},
4040
},
41-
});
41+
})
4242

43-
vm && vm.$on('hook:destroyed', () => computedHost.$destroy());
43+
vm && vm.$on('hook:destroyed', () => computedHost.$destroy())
4444

4545
return createRef<T>({
4646
get: () => (computedHost as any).$$state,
4747
set: (v: T) => {
4848
if (__DEV__ && !set) {
49-
warn('Computed property was assigned to but it has no setter.', vm!);
50-
return;
49+
warn('Computed property was assigned to but it has no setter.', vm!)
50+
return
5151
}
5252

53-
(computedHost as any).$$state = v;
53+
;(computedHost as any).$$state = v
5454
},
55-
});
55+
})
5656
}

src/apis/inject.ts

Lines changed: 31 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -1,59 +1,65 @@
1-
import { ComponentInstance } from '../component';
2-
import { currentVMInFn } from '../helper';
3-
import { hasOwn, warn } from '../utils';
4-
import { getCurrentVM } from '../runtimeContext';
1+
import { ComponentInstance } from '../component'
2+
import { currentVMInFn } from '../helper'
3+
import { hasOwn, warn } from '../utils'
4+
import { getCurrentVM } from '../runtimeContext'
55

6-
const NOT_FOUND = {};
6+
const NOT_FOUND = {}
77
export interface InjectionKey<T> extends Symbol {}
88

9-
function resolveInject(provideKey: InjectionKey<any> | string, vm: ComponentInstance): any {
10-
let source = vm;
9+
function resolveInject(
10+
provideKey: InjectionKey<any> | string,
11+
vm: ComponentInstance
12+
): any {
13+
let source = vm
1114
while (source) {
1215
// @ts-ignore
1316
if (source._provided && hasOwn(source._provided, provideKey)) {
1417
//@ts-ignore
15-
return source._provided[provideKey];
18+
return source._provided[provideKey]
1619
}
17-
source = source.$parent;
20+
source = source.$parent
1821
}
1922

20-
return NOT_FOUND;
23+
return NOT_FOUND
2124
}
2225

2326
export function provide<T>(key: InjectionKey<T> | string, value: T): void {
24-
const vm: any = currentVMInFn('provide');
25-
if (!vm) return;
27+
const vm: any = currentVMInFn('provide')
28+
if (!vm) return
2629

2730
if (!vm._provided) {
28-
const provideCache = {};
31+
const provideCache = {}
2932
Object.defineProperty(vm, '_provided', {
3033
get: () => provideCache,
3134
set: (v) => Object.assign(provideCache, v),
32-
});
35+
})
3336
}
3437

35-
vm._provided[key as string] = value;
38+
vm._provided[key as string] = value
3639
}
3740

38-
export function inject<T>(key: InjectionKey<T> | string): T | undefined;
39-
export function inject<T>(key: InjectionKey<T> | string, defaultValue: T): T;
40-
export function inject(key: InjectionKey<any> | string, defaultValue?: unknown) {
41+
export function inject<T>(key: InjectionKey<T> | string): T | undefined
42+
export function inject<T>(key: InjectionKey<T> | string, defaultValue: T): T
43+
export function inject(
44+
key: InjectionKey<any> | string,
45+
defaultValue?: unknown
46+
) {
4147
if (!key) {
42-
return defaultValue;
48+
return defaultValue
4349
}
4450

45-
const vm = getCurrentVM();
51+
const vm = getCurrentVM()
4652
if (vm) {
47-
const val = resolveInject(key, vm);
53+
const val = resolveInject(key, vm)
4854
if (val !== NOT_FOUND) {
49-
return val;
55+
return val
5056
} else {
5157
if (defaultValue === undefined && process.env.NODE_ENV !== 'production') {
52-
warn(`Injection "${String(key)}" not found`, vm);
58+
warn(`Injection "${String(key)}" not found`, vm)
5359
}
54-
return defaultValue;
60+
return defaultValue
5561
}
5662
} else {
57-
warn(`inject() can only be used inside setup() or functional components.`);
63+
warn(`inject() can only be used inside setup() or functional components.`)
5864
}
5965
}

src/apis/lifecycle.ts

Lines changed: 32 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -1,44 +1,49 @@
1-
import { VueConstructor } from 'vue';
2-
import { ComponentInstance } from '../component';
3-
import { getCurrentVue, setCurrentVM, getCurrentVM } from '../runtimeContext';
4-
import { currentVMInFn } from '../helper';
1+
import { VueConstructor } from 'vue'
2+
import { ComponentInstance } from '../component'
3+
import { getCurrentVue, setCurrentVM, getCurrentVM } from '../runtimeContext'
4+
import { currentVMInFn } from '../helper'
55

6-
const genName = (name: string) => `on${name[0].toUpperCase() + name.slice(1)}`;
6+
const genName = (name: string) => `on${name[0].toUpperCase() + name.slice(1)}`
77
function createLifeCycle(lifeCyclehook: string) {
88
return (callback: Function) => {
9-
const vm = currentVMInFn(genName(lifeCyclehook));
9+
const vm = currentVMInFn(genName(lifeCyclehook))
1010
if (vm) {
11-
injectHookOption(getCurrentVue(), vm, lifeCyclehook, callback);
11+
injectHookOption(getCurrentVue(), vm, lifeCyclehook, callback)
1212
}
13-
};
13+
}
1414
}
1515

16-
function injectHookOption(Vue: VueConstructor, vm: ComponentInstance, hook: string, val: Function) {
17-
const options = vm.$options as any;
18-
const mergeFn = Vue.config.optionMergeStrategies[hook];
19-
options[hook] = mergeFn(options[hook], wrapHookCall(vm, val));
16+
function injectHookOption(
17+
Vue: VueConstructor,
18+
vm: ComponentInstance,
19+
hook: string,
20+
val: Function
21+
) {
22+
const options = vm.$options as any
23+
const mergeFn = Vue.config.optionMergeStrategies[hook]
24+
options[hook] = mergeFn(options[hook], wrapHookCall(vm, val))
2025
}
2126

2227
function wrapHookCall(vm: ComponentInstance, fn: Function) {
2328
return (...args: any) => {
24-
let preVm = getCurrentVM();
25-
setCurrentVM(vm);
29+
let preVm = getCurrentVM()
30+
setCurrentVM(vm)
2631
try {
27-
return fn(...args);
32+
return fn(...args)
2833
} finally {
29-
setCurrentVM(preVm);
34+
setCurrentVM(preVm)
3035
}
31-
};
36+
}
3237
}
3338

3439
// export const onCreated = createLifeCycle('created');
35-
export const onBeforeMount = createLifeCycle('beforeMount');
36-
export const onMounted = createLifeCycle('mounted');
37-
export const onBeforeUpdate = createLifeCycle('beforeUpdate');
38-
export const onUpdated = createLifeCycle('updated');
39-
export const onBeforeUnmount = createLifeCycle('beforeDestroy');
40-
export const onUnmounted = createLifeCycle('destroyed');
41-
export const onErrorCaptured = createLifeCycle('errorCaptured');
42-
export const onActivated = createLifeCycle('activated');
43-
export const onDeactivated = createLifeCycle('deactivated');
44-
export const onServerPrefetch = createLifeCycle('serverPrefetch');
40+
export const onBeforeMount = createLifeCycle('beforeMount')
41+
export const onMounted = createLifeCycle('mounted')
42+
export const onBeforeUpdate = createLifeCycle('beforeUpdate')
43+
export const onUpdated = createLifeCycle('updated')
44+
export const onBeforeUnmount = createLifeCycle('beforeDestroy')
45+
export const onUnmounted = createLifeCycle('destroyed')
46+
export const onErrorCaptured = createLifeCycle('errorCaptured')
47+
export const onActivated = createLifeCycle('activated')
48+
export const onDeactivated = createLifeCycle('deactivated')
49+
export const onServerPrefetch = createLifeCycle('serverPrefetch')

src/apis/state.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,4 +14,4 @@ export {
1414
toRaw,
1515
shallowRef,
1616
triggerRef,
17-
} from '../reactivity';
17+
} from '../reactivity'

0 commit comments

Comments
 (0)