/
ngxWarehouse.module.ts
43 lines (38 loc) · 995 Bytes
/
ngxWarehouse.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
31
32
33
34
35
36
37
38
39
40
41
42
43
import { NgModule, ModuleWithProviders } from '@angular/core';
import { CommonModule } from '@angular/common';
import * as localforage from 'localforage';
import { WarehouseConfig, DRIVER_TYPE } from './models';
import { Warehouse } from './services';
import { LocalForageToken, WarehouseConfigToken } from './tokens';
import { DEFAULT_CONFIG } from './constants';
import { isNil } from './util';
@NgModule({
imports: [CommonModule],
providers: [
{
provide: LocalForageToken,
useFactory: localforageFactory
},
{
provide: WarehouseConfigToken,
useValue: DEFAULT_CONFIG
},
Warehouse
]
})
export class NgxWarehouseModule {
static configureWarehouse(config: WarehouseConfig): ModuleWithProviders {
return {
ngModule: NgxWarehouseModule,
providers: [
{
provide: WarehouseConfigToken,
useValue: config
}
]
};
}
}
export function localforageFactory(): any {
return localforage;
}