core-native
Version:
A lightweight framework based on React Native + Redux + Redux Saga, in strict TypeScript.
57 lines (56 loc) • 3.09 kB
TypeScript
import { SagaIterator } from "redux-saga";
import { ActionHandler, LifecycleDecoratorFlag, TickIntervalDecoratorFlag } from "./module";
import { ModuleLifecycleListener } from "./platform/Module";
import { State } from "./reducer";
/**
* For latest decorator spec, please ref following:
* https://tc39.github.io/proposal-decorators/#sec-decorator-functions-element-descriptor
* https://github.com/tc39/proposal-decorators/blob/master/METAPROGRAMMING.md
*/
/**
* Decorator type declaration, required by TypeScript
*/
declare type HandlerDecorator = (target: object, propertyKey: string, descriptor: TypedPropertyDescriptor<ActionHandler>) => TypedPropertyDescriptor<ActionHandler>;
declare type LifecycleHandlerDecorator = (target: object, propertyKey: keyof ModuleLifecycleListener, descriptor: TypedPropertyDescriptor<ActionHandler & LifecycleDecoratorFlag>) => TypedPropertyDescriptor<ActionHandler>;
declare type OnTickHandlerDecorator = (target: object, propertyKey: "onTick", descriptor: TypedPropertyDescriptor<ActionHandler & TickIntervalDecoratorFlag>) => TypedPropertyDescriptor<ActionHandler>;
declare type VoidFunctionDecorator = (target: object, propertyKey: string, descriptor: TypedPropertyDescriptor<(...args: any[]) => void>) => TypedPropertyDescriptor<(...args: any[]) => void>;
declare type AnyFunctionDecorator = (target: object, propertyKey: string, descriptor: TypedPropertyDescriptor<(...args: any[]) => any>) => TypedPropertyDescriptor<(...args: any[]) => any>;
declare type HandlerInterceptor<S> = (handler: ActionHandler, rootState: Readonly<S>) => SagaIterator;
declare type FunctionInterceptor<S> = (handler: () => void, rootState: Readonly<S>) => void;
/**
* A helper for ActionHandler functions (Saga)
*/
export declare function createActionHandlerDecorator<S extends State = State>(interceptor: HandlerInterceptor<S>): HandlerDecorator;
/**
* A helper for regular functions
*/
export declare function createRegularDecorator<S extends State = State>(interceptor: FunctionInterceptor<S>): VoidFunctionDecorator;
/**
* To mark state.loading[identifier] during Saga execution
*/
export declare function Loading(identifier?: string): HandlerDecorator;
/**
* To log (Result=OK) this action, including action name and parameters (masked)
*/
export declare function Log(): HandlerDecorator;
/**
* Required decorator when using lifecycle actions, including onRender/onDestroy/...
*/
export declare function Lifecycle(): LifecycleHandlerDecorator;
/**
* Used for onTick action, to specify to tick interval in second
*/
export declare function Interval(second: number): OnTickHandlerDecorator;
/**
* If specified, the Saga action cannot be entered by other threads during execution
* Useful for error handler action
*/
export declare function Mutex(): HandlerDecorator;
/**
* For Regular function ONLY
*
* Throttle the execution of a regular function
*/
export declare function Throttle(millisecond: number): VoidFunctionDecorator;
export declare function Memo(memoKeyGenerator?: (args: any[]) => string): AnyFunctionDecorator;
export {};