forked from redux-offline/redux-offline
-
Notifications
You must be signed in to change notification settings - Fork 0
/
typings.d.ts
150 lines (132 loc) · 4.17 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
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
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;
queue: {
enqueue: (
array: Array<OfflineAction>,
item: OfflineAction,
context: { offline: OfflineState }
) => Array<OfflineAction>,
dequeue: (
array: Array<OfflineAction>,
item: ResultAction,
context: { offline: OfflineState }
) => Array<OfflineAction>,
peek: (
array: Array<OfflineAction>,
item: any,
context: { offline: OfflineState }
) => OfflineAction
};
offlineActionTracker: {
registerAction: (transaction: number) => Promise<any> | (() => void),
resolveAction: (transaction: number, value: any) => void | (() => void),
rejectAction: (transaction: number, error: Error) => void | (() => void)
};
returnPromises?: boolean;
rehydrate?: boolean;
}
}
declare module '@redux-offline/redux-offline/lib/constants' {
export const DEFAULT_ROLLBACK: string;
export const DEFAULT_COMMIT: string;
export const JS_ERROR: string;
export const PERSIST_REHYDRATE: string;
export const RESET_STATE: string;
export const OFFLINE_BUSY: string;
export const OFFLINE_SEND: string;
export const OFFLINE_COMPLETE_RETRY: string;
export const OFFLINE_SCHEDULE_RETRY: string;
export const OFFLINE_STATUS_CHANGED: string;
}
declare module '@redux-offline/redux-offline' {
import { createStore as createReduxStore, Store, StoreEnhancer, Dispatch, Middleware } from 'redux';
import { Config } from '@redux-offline/redux-offline/lib/types';
export const offline: (userConfig: Partial<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: Partial<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: Middleware
});
}