Match-id-7a9e111a1362e0c42f098a02691676c6e05fd91b
This commit is contained in:
parent
bc580894b7
commit
5d8d24ee89
|
@ -13,13 +13,10 @@
|
||||||
* See the Mulan PSL v2 for more details.
|
* See the Mulan PSL v2 for more details.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
// TODO: implement vNode type
|
|
||||||
|
|
||||||
import {IObserver} from './Observer';
|
import {IObserver} from './Observer';
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 一个对象(对象、数组、集合)对应一个Observer
|
* 一个对象(对象、数组、集合)对应一个Observer
|
||||||
*
|
|
||||||
*/
|
*/
|
||||||
export class HooklessObserver implements IObserver {
|
export class HooklessObserver implements IObserver {
|
||||||
|
|
||||||
|
|
|
@ -28,7 +28,8 @@ const handler = {
|
||||||
forEach,
|
forEach,
|
||||||
keys,
|
keys,
|
||||||
values,
|
values,
|
||||||
[Symbol.iterator]: forOf,
|
// 判断Symbol类型,兼容IE
|
||||||
|
[typeof Symbol === 'function' ? Symbol.iterator : '@@iterator']: forOf,
|
||||||
};
|
};
|
||||||
|
|
||||||
export function createCollectionProxy(rawObj: Object, hookObserver = true): Object {
|
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 };
|
return { value: newVal, done };
|
||||||
},
|
},
|
||||||
[Symbol.iterator]() {
|
// 判断Symbol类型,兼容IE
|
||||||
|
[typeof Symbol === 'function' ? Symbol.iterator : '@@iterator']() {
|
||||||
return this;
|
return this;
|
||||||
},
|
},
|
||||||
};
|
};
|
||||||
|
|
|
@ -13,13 +13,13 @@
|
||||||
* See the Mulan PSL v2 for more details.
|
* See the Mulan PSL v2 for more details.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
//@ts-ignore
|
// @ts-ignore
|
||||||
import { useEffect, useRef } from '../../renderer/hooks/HookExternal';
|
import { useEffect, useRef } from '../../renderer/hooks/HookExternal';
|
||||||
import { getProcessingVNode } from '../../renderer/GlobalVar';
|
import { getProcessingVNode } from '../../renderer/GlobalVar';
|
||||||
import { createProxy } from '../proxy/ProxyHandler';
|
import { createProxy } from '../proxy/ProxyHandler';
|
||||||
import readonlyProxy from '../proxy/readonlyProxy';
|
import readonlyProxy from '../proxy/readonlyProxy';
|
||||||
import { Observer } from '../proxy/Observer';
|
import { Observer } from '../proxy/Observer';
|
||||||
import { FunctionComponent, ClassComponent } from '../Constants';
|
import { FunctionComponent, ClassComponent } from '../../renderer/vnode/VNodeTags';
|
||||||
import { VNode } from '../../renderer/Types';
|
import { VNode } from '../../renderer/Types';
|
||||||
|
|
||||||
const storeMap = new Map<string, StoreHandler<any, any, any>>();
|
const storeMap = new Map<string, StoreHandler<any, any, any>>();
|
||||||
|
@ -80,13 +80,11 @@ 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 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 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 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>>(
|
export function createStore<S extends object, A extends UserActions<S>, C extends UserComputedValues<S>>(
|
||||||
config: StoreConfig<S, A, C>
|
config: StoreConfig<S, A, C>
|
||||||
): () => StoreHandler<S, A, C> {
|
): () => StoreHandler<S, A, C> {
|
||||||
//create a local shalow copy to ensure consistency (if user would change the config object after store creation)
|
// create a local shalow copy to ensure consistency (if user would change the config object after store creation)
|
||||||
config = {
|
config = {
|
||||||
id: config.id,
|
id: config.id,
|
||||||
options: config.options,
|
options: config.options,
|
||||||
|
|
|
@ -31,66 +31,3 @@ export interface IObserver {
|
||||||
|
|
||||||
clearByVNode: (vNode: any) => void;
|
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
|
|
||||||
|
|
Loading…
Reference in New Issue