-
Notifications
You must be signed in to change notification settings - Fork 14
/
storage.ts
47 lines (44 loc) · 1.09 KB
/
storage.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
/* eslint-disable @typescript-eslint/no-empty-interface */
import { injectable, inject } from 'reactant';
import {
Storage as BaseReactantStorage,
StorageOptions,
REHYDRATE,
} from 'reactant-storage';
import type {
IStorageOptions as IBaseStorageOptions,
SetStorageOptions,
} from 'reactant-storage';
import { PortDetector } from './portDetector';
import { storageModuleName } from './constants';
export interface IStorageOptions extends IBaseStorageOptions {
//
}
@injectable({
name: storageModuleName,
})
class ReactantStorage extends BaseReactantStorage {
constructor(
protected portDetector: PortDetector,
@inject(StorageOptions) public options: IStorageOptions
) {
super(options);
this.onRehydrated(() => {
this.portDetector.onServer(() => {
this.persistor!.persist();
});
this.portDetector.onClient(() => {
this.persistor!.pause();
});
if (this.portDetector.isServer) {
this.portDetector.syncToClients();
}
});
}
}
export {
ReactantStorage as Storage,
StorageOptions,
REHYDRATE,
SetStorageOptions,
};