Match-id-7a9e111a1362e0c42f098a02691676c6e05fd91b

This commit is contained in:
* 2022-10-25 14:43:20 +08:00 committed by *
parent bc580894b7
commit 5d8d24ee89
4 changed files with 7 additions and 73 deletions

View File

@ -13,13 +13,10 @@
* See the Mulan PSL v2 for more details.
*/
// TODO: implement vNode type
import {IObserver} from './Observer';
/**
* Observer
*
*/
export class HooklessObserver implements IObserver {

View File

@ -28,7 +28,8 @@ const handler = {
forEach,
keys,
values,
[Symbol.iterator]: forOf,
// 判断Symbol类型兼容IE
[typeof Symbol === 'function' ? Symbol.iterator : '@@iterator']: forOf,
};
export function createCollectionProxy(rawObj: Object, hookObserver = true): Object {
@ -214,7 +215,8 @@ function wrapIterator(rawObj: Object, rawIt: { next: () => { value: any; done: b
return { value: newVal, done };
},
[Symbol.iterator]() {
// 判断Symbol类型兼容IE
[typeof Symbol === 'function' ? Symbol.iterator : '@@iterator']() {
return this;
},
};

View File

@ -19,7 +19,7 @@ import { getProcessingVNode } from '../../renderer/GlobalVar';
import { createProxy } from '../proxy/ProxyHandler';
import readonlyProxy from '../proxy/readonlyProxy';
import { Observer } from '../proxy/Observer';
import { FunctionComponent, ClassComponent } from '../Constants';
import { FunctionComponent, ClassComponent } from '../../renderer/vnode/VNodeTags';
import { VNode } from '../../renderer/Types';
const storeMap = new Map<string, StoreHandler<any, any, any>>();
@ -80,8 +80,6 @@ type AsyncAction<T extends ActionFunction<any>, S extends object> = (
type StoreActions<S extends object, A extends UserActions<S>> = { [K in keyof A]: Action<A[K], S> };
type QueuedStoreActions<S extends object, A extends UserActions<S>> = { [K in keyof A]: AsyncAction<A[K], S> };
type ComputedValues<S extends object, C extends UserComputedValues<S>> = { [K in keyof C]: ReturnType<C[K]> };
type PostponedAction = (state: object, ...args: any[]) => Promise<any>;
type PostponedActions = { [key: string]: PostponedAction };
export function createStore<S extends object, A extends UserActions<S>, C extends UserComputedValues<S>>(
config: StoreConfig<S, A, C>

View File

@ -31,66 +31,3 @@ export interface IObserver {
clearByVNode: (vNode: any) => void;
}
type RemoveFirstFromTuple<T extends any[]> =
T['length'] extends 0 ? [] :
(((...b: T) => void) extends (a, ...b: infer I) => void ? I : [])
type UserActions<S extends object> = { [K:string]: ActionFunction<S> };
type UserComputedValues<S extends object> = { [K:string]: ComputedFunction<S> };
type ActionFunction<S extends object> = (state: S, ...args: any[]) => any;
type ComputedFunction<S extends object> = (state: S) => any;
type Action<T extends UserActions<?>> = (...args:RemoveFirstFromTuple<Parameters<T>>)=>ReturnType<T>
type AsyncAction<T extends UserActions<?>> = (...args:RemoveFirstFromTuple<Parameters<T>>)=>Promise<ReturnType<T>>
type StoreActions<S extends object,A extends UserActions<S>> = { [K in keyof A]: Action<A[K]> };
type QueuedStoreActions<S extends object,A extends UserActions<S>> = { [K in keyof A]: AsyncAction<A[K]> };
type ComputedValues<S extends object,C extends UserComputedValues<S>> = { [K in keyof C]: ReturnType<C[K]> };
type PostponedAction = (state: object, ...args: any[]) => Promise<any>;
type PostponedActions = { [key:string]: PostponedAction }
export type StoreHandler<S extends object,A extends UserActions<S>,C extends UserComputedValues<S>> =
{$subscribe: ((listener: () => void) => void),
$unsubscribe: ((listener: () => void) => void),
$state: S,
$config: StoreConfig<S,A,C>,
$queue: QueuedStoreActions<S,A>,
$actions: StoreActions<S,A>,
$computed: ComputedValues<S,C>,
reduxHandler?:ReduxStoreHandler}
&
{[K in keyof S]: S[K]}
&
{[K in keyof A]: Action<A[K]>}
&
{[K in keyof C]: ReturnType<C[K]>}
export type StoreConfig<S extends object,A extends UserActions<S>,C extends UserComputedValues<S>> = {
state?: S,
options?:{suppressHooks?: boolean},
actions?: A,
id?: string,
computed?: C
}
type ReduxStoreHandler = {
reducer:(state:any,action:{type:string})=>any,
dispatch:(action:{type:string})=>void,
getState:()=>any,
subscribe:(listener:()=>void)=>((listener:()=>void)=>void)
replaceReducer: (reducer: (state:any,action:{type:string})=>any)=>void
_horizonXstore: StoreHandler
}
type ReduxAction = {
type:string
}
type ReduxMiddleware = (store:ReduxStoreHandler, extraArgument?:any) =>
(next:((action:ReduxAction)=>any)) =>
(action:(
ReduxAction|
((dispatch:(action:ReduxAction)=>void,store:ReduxStoreHandler,extraArgument?:any)=>any)
)) => ReduxStoreHandler