Skip to content
This repository was archived by the owner on Feb 26, 2024. It is now read-only.

Commit 09747c0

Browse files
authored
docs: commands were not hot after v4.0 (#142)
The README said they were hot; corrected that. Also, unlike other requests, they did not have the latency delay. Now they do rather than make a pointless exception. Also, resetDb command doesn’t return a body so status changed to 201. These minor changes are not worth a release.
1 parent 06bd075 commit 09747c0

File tree

6 files changed

+38
-47
lines changed

6 files changed

+38
-47
lines changed

README.md

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -94,9 +94,6 @@ Example URLs:
9494
commands/config // Get or update this service's config object
9595
```
9696

97-
Commands are "hot", meaning they are always executed immediately
98-
whether or not someone subscribes to the returned observable.
99-
10097
Usage:
10198
```
10299
http.post('commands/resetdb', undefined);
@@ -249,6 +246,7 @@ See the `handleRequest` method implementation for details.
249246

250247
By default this service adds a 500ms delay (see `InMemoryBackendConfig.delay`)
251248
to all requests to simulate round-trip latency.
249+
252250
You can eliminate that or extend it by setting a different value:
253251
```ts
254252
InMemoryWebApiModule.forRoot(InMemHeroService, { delay: 0 }), // no delay

backend.service.d.ts

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -63,12 +63,9 @@ export declare abstract class BackendService {
6363
/**
6464
* When the last segment of the `base` path is "commands", the `collectionName` is the command
6565
* Example URLs:
66-
* commands/resetdb // Reset the "database" to its original state
67-
* commands/config (GET) // Return this service's config object
68-
* commands/config (!GET) // Update the config (e.g. delay)
69-
*
70-
* Commands are "hot", meaning they are always executed immediately
71-
* whether or not someone subscribes to the returned observable
66+
* commands/resetdb (POST) // Reset the "database" to its original state
67+
* commands/config (GET) // Return this service's config object
68+
* commands/config (POST) // Update the config (e.g. the delay)
7269
*
7370
* Usage:
7471
* http.post('commands/resetdb', undefined);

backend.service.js

Lines changed: 10 additions & 12 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

backend.service.js.map

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

bundles/in-memory-web-api.umd.js

Lines changed: 11 additions & 13 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/in-mem/backend.service.ts

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -239,12 +239,9 @@ export abstract class BackendService {
239239
/**
240240
* When the last segment of the `base` path is "commands", the `collectionName` is the command
241241
* Example URLs:
242-
* commands/resetdb // Reset the "database" to its original state
243-
* commands/config (GET) // Return this service's config object
244-
* commands/config (!GET) // Update the config (e.g. delay)
245-
*
246-
* Commands are "hot", meaning they are always executed immediately
247-
* whether or not someone subscribes to the returned observable
242+
* commands/resetdb (POST) // Reset the "database" to its original state
243+
* commands/config (GET) // Return this service's config object
244+
* commands/config (POST) // Update the config (e.g. the delay)
248245
*
249246
* Usage:
250247
* http.post('commands/resetdb', undefined);
@@ -256,25 +253,28 @@ export abstract class BackendService {
256253
const method = reqInfo.method;
257254

258255
let resOptions: ResponseOptions = {
259-
status: STATUS.OK,
260256
url: reqInfo.url
261257
};
262258

263259
switch (command) {
264260
case 'resetdb':
261+
resOptions.status = STATUS.NO_CONTENT;
265262
return concatMap.call(
266263
this.resetDb(reqInfo),
267-
() => this.createResponse$(() => resOptions, false /* no delay */));
264+
() => this.createResponse$(() => resOptions));
268265

269266
case 'config':
270267
if (method === 'get') {
268+
resOptions.status = STATUS.OK;
271269
resOptions.body = this.clone(this.config);
270+
271+
// any other HTTP method is assumed to be a config update
272272
} else {
273-
// any other HTTP method is assumed to be a config update
274-
resOptions.status = STATUS.NO_CONTENT;
275273
const body = this.getJsonBody(reqInfo.req);
276274
Object.assign(this.config, body);
277-
this.passThruBackend = undefined; // re-create next time
275+
this.passThruBackend = undefined; // re-create when needed
276+
277+
resOptions.status = STATUS.NO_CONTENT;
278278
}
279279
break;
280280

@@ -286,7 +286,7 @@ export abstract class BackendService {
286286
);
287287
}
288288

289-
return this.createResponse$(() => resOptions, false /* no delay */);
289+
return this.createResponse$(() => resOptions);
290290
}
291291

292292
protected createErrorResponseOptions(url: string, status: number, message: string): ResponseOptions {

0 commit comments

Comments
 (0)