forked from dart-wakar/ngx-dexie
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdexie.module.ts
30 lines (25 loc) · 876 Bytes
/
dexie.module.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
import {NgModule,ModuleWithProviders,InjectionToken} from '@angular/core';
import {DexieDatabase} from './dexie.database';
import {DexieService} from './dexie.service';
import {DexieConfig} from './dexieConfig';
export function DexieFactory(config: DexieConfig) {
return new DexieDatabase(config);
}
export const DEXIE_CONFIG_TOKEN = new InjectionToken<DexieConfig>('__DEXIE_CONFIG__');
@NgModule({})
export class DexieModule {
static forRoot(config: DexieConfig): ModuleWithProviders {
return {
ngModule: DexieModule,
providers: [
{provide: DEXIE_CONFIG_TOKEN,useValue: config},
{
provide: DexieDatabase,
useFactory: DexieFactory,
deps: [DEXIE_CONFIG_TOKEN]
},
DexieService
]
};
}
}