This repository has been archived by the owner on Feb 26, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 231
/
http-client-in-memory-web-api.module.js
65 lines (65 loc) · 3.3 KB
/
http-client-in-memory-web-api.module.js
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
////// HttpClient-Only version ////
var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
return c > 3 && r && Object.defineProperty(target, key, r), r;
};
import { NgModule } from '@angular/core';
import { HttpBackend, XhrFactory } from '@angular/common/http';
import { InMemoryBackendConfig, InMemoryDbService } from './interfaces';
import { HttpClientBackendService } from './http-client-backend.service';
// Internal - Creates the in-mem backend for the HttpClient module
// AoT requires factory to be exported
export function httpClientInMemBackendServiceFactory(dbService, options, xhrFactory) {
var backend = new HttpClientBackendService(dbService, options, xhrFactory);
return backend;
}
var HttpClientInMemoryWebApiModule = /** @class */ (function () {
function HttpClientInMemoryWebApiModule() {
}
HttpClientInMemoryWebApiModule_1 = HttpClientInMemoryWebApiModule;
/**
* Redirect the Angular `HttpClient` XHR calls
* to in-memory data store that implements `InMemoryDbService`.
* with class that implements InMemoryDbService and creates an in-memory database.
*
* Usually imported in the root application module.
* Can import in a lazy feature module too, which will shadow modules loaded earlier
*
* @param {Type} dbCreator - Class that creates seed data for in-memory database. Must implement InMemoryDbService.
* @param {InMemoryBackendConfigArgs} [options]
*
* @example
* HttpInMemoryWebApiModule.forRoot(dbCreator);
* HttpInMemoryWebApiModule.forRoot(dbCreator, {useValue: {delay:600}});
*/
HttpClientInMemoryWebApiModule.forRoot = function (dbCreator, options) {
return {
ngModule: HttpClientInMemoryWebApiModule_1,
providers: [
{ provide: InMemoryDbService, useClass: dbCreator },
{ provide: InMemoryBackendConfig, useValue: options },
{ provide: HttpBackend,
useFactory: httpClientInMemBackendServiceFactory,
deps: [InMemoryDbService, InMemoryBackendConfig, XhrFactory] }
]
};
};
/**
*
* Enable and configure the in-memory web api in a lazy-loaded feature module.
* Same as `forRoot`.
* This is a feel-good method so you can follow the Angular style guide for lazy-loaded modules.
*/
HttpClientInMemoryWebApiModule.forFeature = function (dbCreator, options) {
return HttpClientInMemoryWebApiModule_1.forRoot(dbCreator, options);
};
var HttpClientInMemoryWebApiModule_1;
HttpClientInMemoryWebApiModule = HttpClientInMemoryWebApiModule_1 = __decorate([
NgModule({})
], HttpClientInMemoryWebApiModule);
return HttpClientInMemoryWebApiModule;
}());
export { HttpClientInMemoryWebApiModule };
//# sourceMappingURL=http-client-in-memory-web-api.module.js.map