@rematch/loading
Version:
Loading indicator plugin for Rematch
42 lines • 2 kB
TypeScript
import { ExtractRematchDispatchersFromEffects, Plugin, Models, Reducer, NamedModel } from '@rematch/core';
export declare type LoadingPluginType = 'number' | 'boolean' | 'full';
export interface LoadingConfig {
name?: string;
whitelist?: string[];
blacklist?: string[];
type?: LoadingPluginType;
asNumber?: boolean;
}
declare type PickLoadingPluginType<WhichType extends LoadingPluginType> = WhichType extends 'number' ? number : WhichType extends 'full' ? DetailedPayload : boolean;
interface LoadingState<TModels extends Models<TModels>, WhichType extends LoadingPluginType> {
global: PickLoadingPluginType<WhichType>;
models: {
[modelName in keyof TModels]: PickLoadingPluginType<WhichType>;
};
effects: {
[modelName in keyof TModels]: {
[effectName in keyof ExtractRematchDispatchersFromEffects<TModels[modelName]['effects'], TModels>]: PickLoadingPluginType<WhichType>;
};
};
}
interface LoadingModel<TModels extends Models<TModels>, WhichType extends LoadingPluginType> extends NamedModel<TModels, LoadingState<TModels, WhichType>> {
reducers: {
hide: Reducer<LoadingState<TModels, WhichType>>;
show: Reducer<LoadingState<TModels, WhichType>>;
};
}
export interface ExtraModelsFromLoading<TModels extends Models<TModels>, TConfig extends LoadingConfig = {
type: 'boolean';
}> extends Models<TModels> {
loading: LoadingModel<TModels, TConfig['type'] extends LoadingPluginType ? TConfig['type'] : 'boolean'>;
}
declare type DetailedPayload = {
error: unknown;
success: boolean;
loading?: boolean;
};
declare const _default: <TModels extends Models<TModels>, TExtraModels extends Models<TModels>, TConfig extends LoadingConfig>(config?: TConfig) => Plugin<TModels, TExtraModels, ExtraModelsFromLoading<TModels, TConfig extends LoadingConfig ? TConfig : {
type: 'boolean';
}>>;
export default _default;
//# sourceMappingURL=index.d.ts.map