forked from sorodrigo/redux-offline
-
Notifications
You must be signed in to change notification settings - Fork 0
/
typings.d.ts
113 lines (96 loc) · 2.96 KB
/
typings.d.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
declare module '@redux-offline/redux-offline/lib/defaults' {
import { Config } from '@redux-offline/redux-offline/lib/types';
const config: Config;
export default config;
}
declare module '@redux-offline/redux-offline/lib/types' {
export interface ResultAction {
meta: {
completed: boolean;
success: boolean;
};
payload?: object;
type: string;
}
export interface OfflineMetadata {
commit: ResultAction;
effect: object;
rollback: ResultAction;
}
export interface OfflineAction {
meta: {
offline: OfflineMetadata;
transaction?: number;
};
payload?: object;
type: string;
}
export interface NetInfo {
isConnectionExpensive?: boolean;
reach: string;
}
export interface OfflineStatusChangeAction {
payload: {
netInfo?: NetInfo;
online: boolean;
};
type: string;
}
export interface OfflineScheduleRetryAction {
type: string;
}
export type Outbox = OfflineAction[];
export interface OfflineState {
busy: boolean;
lastTransaction: number;
netInfo?: NetInfo;
online: boolean;
outbox: Outbox;
retryCount: number;
retryScheduled: boolean;
}
export interface PersistRehydrateAction {
payload: {
offline: OfflineState;
};
type: string;
}
export interface AppState {
offline: OfflineState;
}
export type NetworkCallback = (result: boolean) => void;
export interface Config {
defaultCommit: { type: string };
defaultRollback: { type: string };
detectNetwork: (callback: NetworkCallback) => void;
discard: (error: any, action: OfflineAction, retries: number) => boolean;
effect: (effect: any, action: OfflineAction) => Promise<any>;
offlineStateLens: (
state: any,
) => { get: OfflineState, set: (offlineState?: OfflineState) => any };
persist: (store: any) => any;
persistAutoRehydrate: (config?: { [key: string]: any }) => (next: any) => any;
persistCallback: (callback?: any) => any;
persistOptions: { [key: string]: any };
retry: (action: OfflineAction, retries: number) => number | void;
}
}
declare module '@redux-offline/redux-offline' {
import { createStore as createReduxStore, Store, StoreEnhancer } from 'redux';
import { Config } from '@redux-offline/redux-offline/lib/types';
export const offline: (userConfig: Config) => (createStore: typeof createReduxStore) =>
<T extends { [key: string]: any }>(
reducer: (state: T, action: any) => T,
preloadedState: T,
enhancer: StoreEnhancer<T>,
) => Store<T>;
export const createOffline: (userConfig: Config) => ({
enhanceReducer: (reducer: any) => (state: any, action: any) => any,
enhanceStore: (next: any) => <T extends { [key: string]: any }>(
reducer: (state: T, action: any) => T,
preloadedState: T,
enhancer: StoreEnhancer<T>,
) => Store<T>,
middleware: <A = any, R = any>(store: any) => (next: (action: A) => R) => (action: A) => R,
});
}