-
Notifications
You must be signed in to change notification settings - Fork 98
Expand file tree
/
Copy pathindex.ts
More file actions
72 lines (56 loc) · 1.7 KB
/
Copy pathindex.ts
File metadata and controls
72 lines (56 loc) · 1.7 KB
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
import { isPlatformServer } from '@angular/common';
import type { ModuleWithProviders } from '@angular/core';
import { InjectionToken, NgModule, PLATFORM_ID } from '@angular/core';
import { Storage, StorageConfig } from '@ionic/storage';
const StorageConfigToken = new InjectionToken<any>('STORAGE_CONFIG_TOKEN');
export { StorageConfig, StorageConfigToken, Storage };
class NoopStorage extends Storage {
constructor() {
super();
}
async create() {
return this;
}
async defineDriver() {}
get driver(): string | null {
return 'noop';
}
async get(key: string) {
return null;
}
async set(key: string, value: any) {}
async remove(key: string): Promise<any> {}
async clear(): Promise<void> {}
async length(): Promise<number> {
return 0;
}
async keys() {
return [];
}
// eslint-disable-next-line @typescript-eslint/ban-types
async forEach(iteratorCallback: (value: any, key: string, iterationNumber: Number) => any): Promise<void> {}
setEncryptionKey(key: string) {}
}
export function provideStorage(platformId: any, storageConfig: StorageConfig): Storage {
if (isPlatformServer(platformId)) {
// When running in a server context return the NoopStorage
return new NoopStorage();
}
return new Storage(storageConfig);
}
@NgModule()
export class IonicStorageModule {
static forRoot(storageConfig: StorageConfig = null): ModuleWithProviders<IonicStorageModule> {
return {
ngModule: IonicStorageModule,
providers: [
{ provide: StorageConfigToken, useValue: storageConfig },
{
provide: Storage,
useFactory: provideStorage,
deps: [PLATFORM_ID, StorageConfigToken],
},
],
};
}
}