@geosdi/ngx-model 1.2.2 → 1.2.4
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +70 -13
- package/fesm2022/geosdi-ngx-model.mjs.map +1 -1
- package/package.json +4 -3
- package/types/geosdi-ngx-model.d.ts +58 -0
- package/index.d.ts +0 -4
- package/lib/ngx-chain-handler.d.ts +0 -11
- package/lib/ngx-colleague.d.ts +0 -16
- package/lib/ngx-mediator.service.d.ts +0 -19
- package/lib/ngx-model.d.ts +0 -7
package/README.md
CHANGED
|
@@ -1,24 +1,81 @@
|
|
|
1
|
-
#
|
|
1
|
+
# @geosdi/ngx-model
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
The building blocks of two design patterns, plus a base model: a **chain of responsibility**
|
|
4
|
+
(`NgxChainHandler`) and a **mediator** with its colleagues (`NgxMediator`, `NgxColleague`). Plain
|
|
5
|
+
TypeScript: no Angular, no dependencies.
|
|
4
6
|
|
|
5
|
-
##
|
|
7
|
+
## Installation
|
|
6
8
|
|
|
7
|
-
|
|
8
|
-
> Note: Don't forget to add `--project ngx-model` or else it will be added to the default project in your `angular.json` file.
|
|
9
|
+
`npm i @geosdi/ngx-model --save`
|
|
9
10
|
|
|
10
|
-
|
|
11
|
+
It has no dependencies.
|
|
11
12
|
|
|
12
|
-
|
|
13
|
+
## Chain of responsibility
|
|
13
14
|
|
|
14
|
-
|
|
15
|
+
`NgxChainHandler<B>` holds the next handler of the chain. Each handler decides whether it handles the
|
|
16
|
+
input or passes it on to `_successor`; the library gives the link, the method is yours.
|
|
15
17
|
|
|
16
|
-
|
|
18
|
+
```typescript
|
|
19
|
+
import { NgxChainHandler } from "@geosdi/ngx-model";
|
|
17
20
|
|
|
18
|
-
|
|
21
|
+
abstract class StyleHandler extends NgxChainHandler<StyleHandler> {
|
|
22
|
+
abstract style(feature: Feature): PathOptions;
|
|
19
23
|
|
|
20
|
-
|
|
24
|
+
protected forward(feature: Feature): PathOptions {
|
|
25
|
+
return this._successor ? this._successor.style(feature) : {};
|
|
26
|
+
}
|
|
27
|
+
}
|
|
21
28
|
|
|
22
|
-
|
|
29
|
+
class BuildingHandler extends StyleHandler {
|
|
30
|
+
style(feature: Feature): PathOptions {
|
|
31
|
+
return feature.properties.type === "building"
|
|
32
|
+
? { color: "blue" }
|
|
33
|
+
: this.forward(feature);
|
|
34
|
+
}
|
|
35
|
+
}
|
|
23
36
|
|
|
24
|
-
|
|
37
|
+
const first = new BuildingHandler();
|
|
38
|
+
first.successor = new AggregateHandler();
|
|
39
|
+
first.style(feature);
|
|
40
|
+
```
|
|
41
|
+
|
|
42
|
+
- the type parameter is the handler's own base type, so `_successor` has the same methods as the
|
|
43
|
+
handler that calls it;
|
|
44
|
+
- `successor` has only a setter: subclasses read `_successor`, which is `protected`;
|
|
45
|
+
- the last handler of the chain has no successor, so decide what it returns when nothing matched.
|
|
46
|
+
|
|
47
|
+
## Mediator
|
|
48
|
+
|
|
49
|
+
`NgxMediator<C>` receives the colleagues and finds them by key. A colleague is anything that
|
|
50
|
+
implements `INgxColleague` — a `getKey()` — or extends `NgxColleague`.
|
|
51
|
+
|
|
52
|
+
```typescript
|
|
53
|
+
import { NgxColleague, NgxMediator } from "@geosdi/ngx-model";
|
|
54
|
+
|
|
55
|
+
class DeleteAction extends NgxColleague {
|
|
56
|
+
getKey(): string {
|
|
57
|
+
return "delete";
|
|
58
|
+
}
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
const mediator = new NgxMediator<NgxColleague>([
|
|
62
|
+
new DeleteAction(),
|
|
63
|
+
new SplitAction(),
|
|
64
|
+
]);
|
|
65
|
+
mediator.getColleague("delete"); // the DeleteAction
|
|
66
|
+
mediator.getColleague("missing"); // null
|
|
67
|
+
```
|
|
68
|
+
|
|
69
|
+
- the colleagues are indexed once, in the constructor: to change them, build a new mediator;
|
|
70
|
+
- **two colleagues with the same key**: the last one wins, with no warning;
|
|
71
|
+
- `getColleague` returns `null` for an unknown key;
|
|
72
|
+
- `NgxMediator` is a plain class, not an Angular service: to inject it, provide it yourself (for
|
|
73
|
+
instance with a `useFactory` that receives the colleagues).
|
|
74
|
+
|
|
75
|
+
## Model
|
|
76
|
+
|
|
77
|
+
`Model` is the base interface of an entity: an optional `id`, a string or a number.
|
|
78
|
+
|
|
79
|
+
## Changes in 1.2.4
|
|
80
|
+
|
|
81
|
+
- This README, which replaces the one generated by Angular CLI. The code is unchanged.
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"geosdi-ngx-model.mjs","sources":["../../../../projects/geosdi/support/ngx-model/src/lib/ngx-chain-handler.ts","../../../../projects/geosdi/support/ngx-model/src/lib/ngx-colleague.ts","../../../../projects/geosdi/support/ngx-model/src/lib/ngx-mediator.service.ts","../../../../projects/geosdi/support/ngx-model/src/index.ts","../../../../projects/geosdi/support/ngx-model/src/geosdi-ngx-model.ts"],"sourcesContent":["/**\n * @author Vito Salvia - CNR IMAA geoSDI Group\n * @email vito.salvia@gmail.com\n */\nexport abstract class NgxChainHandler<B extends NgxChainHandler<B>> {\n protected _successor: B;\n\n /**\n *\n */\n public set successor(_successor: B) {\n this._successor = _successor;\n }\n}\n","/**\n * @author Vito Salvia - CNR IMAA geoSDI Group\n * @email vito.salvia@gmail.com\n */\nexport interface INgxColleague {\n /**\n *\n */\n getKey(): any;\n}\n\nexport abstract class NgxColleague implements INgxColleague {\n /**\n *\n */\n abstract getKey(): any;\n}\n","import { INgxColleague } from \"./ngx-colleague\";\n\n/**\n * @author Vito Salvia - CNR IMAA geoSDI Group\n * @email vito.salvia@gmail.com\n */\nexport class NgxMediator<C extends INgxColleague> {\n protected colleaguesMap: Map<string, C> = new Map();\n\n constructor(private colleagues: ReadonlyArray<C>) {\n this.initColleagues();\n }\n\n /**\n *\n */\n initColleagues() {\n this.colleagues.forEach((c) => {\n this.colleaguesMap.set(c.getKey(), c);\n });\n }\n\n /**\n *\n * @param key\n */\n getColleague(key: string) {\n return this.colleaguesMap.has(key) ? this.colleaguesMap.get(key) : null;\n }\n}\n","/*\n * Public API Surface of ngx-model\n */\n\nexport * from \"./lib/ngx-model\";\nexport * from \"./lib/ngx-chain-handler\";\nexport * from \"./lib/ngx-colleague\";\nexport * from \"./lib/ngx-mediator.service\";\n","/**\n * Generated bundle index. Do not edit.\n */\n\nexport * from './index';\n"],"names":[],"mappings":"AAAA;;;AAGG;MACmB,eAAe,CAAA;AAGjC;;AAEG;IACH,IAAW,SAAS,CAAC,UAAa,EAAA;AAC9B,QAAA,IAAI,CAAC,UAAU,GAAG,UAAU;;
|
|
1
|
+
{"version":3,"file":"geosdi-ngx-model.mjs","sources":["../../../../projects/geosdi/support/ngx-model/src/lib/ngx-chain-handler.ts","../../../../projects/geosdi/support/ngx-model/src/lib/ngx-colleague.ts","../../../../projects/geosdi/support/ngx-model/src/lib/ngx-mediator.service.ts","../../../../projects/geosdi/support/ngx-model/src/index.ts","../../../../projects/geosdi/support/ngx-model/src/geosdi-ngx-model.ts"],"sourcesContent":["/**\n * @author Vito Salvia - CNR IMAA geoSDI Group\n * @email vito.salvia@gmail.com\n */\nexport abstract class NgxChainHandler<B extends NgxChainHandler<B>> {\n protected _successor: B;\n\n /**\n *\n */\n public set successor(_successor: B) {\n this._successor = _successor;\n }\n}\n","/**\n * @author Vito Salvia - CNR IMAA geoSDI Group\n * @email vito.salvia@gmail.com\n */\nexport interface INgxColleague {\n /**\n *\n */\n getKey(): any;\n}\n\nexport abstract class NgxColleague implements INgxColleague {\n /**\n *\n */\n abstract getKey(): any;\n}\n","import { INgxColleague } from \"./ngx-colleague\";\n\n/**\n * @author Vito Salvia - CNR IMAA geoSDI Group\n * @email vito.salvia@gmail.com\n */\nexport class NgxMediator<C extends INgxColleague> {\n protected colleaguesMap: Map<string, C> = new Map();\n\n constructor(private colleagues: ReadonlyArray<C>) {\n this.initColleagues();\n }\n\n /**\n *\n */\n initColleagues() {\n this.colleagues.forEach((c) => {\n this.colleaguesMap.set(c.getKey(), c);\n });\n }\n\n /**\n *\n * @param key\n */\n getColleague(key: string) {\n return this.colleaguesMap.has(key) ? this.colleaguesMap.get(key) : null;\n }\n}\n","/*\n * Public API Surface of ngx-model\n */\n\nexport * from \"./lib/ngx-model\";\nexport * from \"./lib/ngx-chain-handler\";\nexport * from \"./lib/ngx-colleague\";\nexport * from \"./lib/ngx-mediator.service\";\n","/**\n * Generated bundle index. Do not edit.\n */\n\nexport * from './index';\n"],"names":[],"mappings":"AAAA;;;AAGG;MACmB,eAAe,CAAA;AAGjC;;AAEG;IACH,IAAW,SAAS,CAAC,UAAa,EAAA;AAC9B,QAAA,IAAI,CAAC,UAAU,GAAG,UAAU;IAChC;AACH;;MCFqB,YAAY,CAAA;AAKjC;;ACdD;;;AAGG;MACU,WAAW,CAAA;AAGpB,IAAA,WAAA,CAAoB,UAA4B,EAAA;QAA5B,IAAA,CAAA,UAAU,GAAV,UAAU;AAFpB,QAAA,IAAA,CAAA,aAAa,GAAmB,IAAI,GAAG,EAAE;QAG/C,IAAI,CAAC,cAAc,EAAE;IACzB;AAEA;;AAEG;IACH,cAAc,GAAA;QACV,IAAI,CAAC,UAAU,CAAC,OAAO,CAAC,CAAC,CAAC,KAAI;AAC1B,YAAA,IAAI,CAAC,aAAa,CAAC,GAAG,CAAC,CAAC,CAAC,MAAM,EAAE,EAAE,CAAC,CAAC;AACzC,QAAA,CAAC,CAAC;IACN;AAEA;;;AAGG;AACH,IAAA,YAAY,CAAC,GAAW,EAAA;QACpB,OAAO,IAAI,CAAC,aAAa,CAAC,GAAG,CAAC,GAAG,CAAC,GAAG,IAAI,CAAC,aAAa,CAAC,GAAG,CAAC,GAAG,CAAC,GAAG,IAAI;IAC3E;AACH;;AC7BD;;AAEG;;ACFH;;AAEG;;;;"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@geosdi/ngx-model",
|
|
3
|
-
"version": "1.2.
|
|
3
|
+
"version": "1.2.4",
|
|
4
4
|
"description": "Model class",
|
|
5
5
|
"author": "Salvia Vito (vito.salvia@gmail.com)",
|
|
6
6
|
"keywords": [
|
|
@@ -8,16 +8,17 @@
|
|
|
8
8
|
],
|
|
9
9
|
"sideEffects": false,
|
|
10
10
|
"module": "fesm2022/geosdi-ngx-model.mjs",
|
|
11
|
-
"typings": "
|
|
11
|
+
"typings": "types/geosdi-ngx-model.d.ts",
|
|
12
12
|
"exports": {
|
|
13
13
|
"./package.json": {
|
|
14
14
|
"default": "./package.json"
|
|
15
15
|
},
|
|
16
16
|
".": {
|
|
17
|
-
"types": "./
|
|
17
|
+
"types": "./types/geosdi-ngx-model.d.ts",
|
|
18
18
|
"default": "./fesm2022/geosdi-ngx-model.mjs"
|
|
19
19
|
}
|
|
20
20
|
},
|
|
21
|
+
"type": "module",
|
|
21
22
|
"dependencies": {
|
|
22
23
|
"tslib": "^2.3.0"
|
|
23
24
|
}
|
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @author Vito Salvia - CNR IMAA geoSDI Group
|
|
3
|
+
* @email vito.salvia@gmail.com
|
|
4
|
+
*/
|
|
5
|
+
interface Model {
|
|
6
|
+
id?: string | number | null;
|
|
7
|
+
}
|
|
8
|
+
|
|
9
|
+
/**
|
|
10
|
+
* @author Vito Salvia - CNR IMAA geoSDI Group
|
|
11
|
+
* @email vito.salvia@gmail.com
|
|
12
|
+
*/
|
|
13
|
+
declare abstract class NgxChainHandler<B extends NgxChainHandler<B>> {
|
|
14
|
+
protected _successor: B;
|
|
15
|
+
/**
|
|
16
|
+
*
|
|
17
|
+
*/
|
|
18
|
+
set successor(_successor: B);
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
/**
|
|
22
|
+
* @author Vito Salvia - CNR IMAA geoSDI Group
|
|
23
|
+
* @email vito.salvia@gmail.com
|
|
24
|
+
*/
|
|
25
|
+
interface INgxColleague {
|
|
26
|
+
/**
|
|
27
|
+
*
|
|
28
|
+
*/
|
|
29
|
+
getKey(): any;
|
|
30
|
+
}
|
|
31
|
+
declare abstract class NgxColleague implements INgxColleague {
|
|
32
|
+
/**
|
|
33
|
+
*
|
|
34
|
+
*/
|
|
35
|
+
abstract getKey(): any;
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
/**
|
|
39
|
+
* @author Vito Salvia - CNR IMAA geoSDI Group
|
|
40
|
+
* @email vito.salvia@gmail.com
|
|
41
|
+
*/
|
|
42
|
+
declare class NgxMediator<C extends INgxColleague> {
|
|
43
|
+
private colleagues;
|
|
44
|
+
protected colleaguesMap: Map<string, C>;
|
|
45
|
+
constructor(colleagues: ReadonlyArray<C>);
|
|
46
|
+
/**
|
|
47
|
+
*
|
|
48
|
+
*/
|
|
49
|
+
initColleagues(): void;
|
|
50
|
+
/**
|
|
51
|
+
*
|
|
52
|
+
* @param key
|
|
53
|
+
*/
|
|
54
|
+
getColleague(key: string): C;
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
export { NgxChainHandler, NgxColleague, NgxMediator };
|
|
58
|
+
export type { INgxColleague, Model };
|
package/index.d.ts
DELETED
package/lib/ngx-colleague.d.ts
DELETED
|
@@ -1,16 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* @author Vito Salvia - CNR IMAA geoSDI Group
|
|
3
|
-
* @email vito.salvia@gmail.com
|
|
4
|
-
*/
|
|
5
|
-
export interface INgxColleague {
|
|
6
|
-
/**
|
|
7
|
-
*
|
|
8
|
-
*/
|
|
9
|
-
getKey(): any;
|
|
10
|
-
}
|
|
11
|
-
export declare abstract class NgxColleague implements INgxColleague {
|
|
12
|
-
/**
|
|
13
|
-
*
|
|
14
|
-
*/
|
|
15
|
-
abstract getKey(): any;
|
|
16
|
-
}
|
|
@@ -1,19 +0,0 @@
|
|
|
1
|
-
import { INgxColleague } from "./ngx-colleague";
|
|
2
|
-
/**
|
|
3
|
-
* @author Vito Salvia - CNR IMAA geoSDI Group
|
|
4
|
-
* @email vito.salvia@gmail.com
|
|
5
|
-
*/
|
|
6
|
-
export declare class NgxMediator<C extends INgxColleague> {
|
|
7
|
-
private colleagues;
|
|
8
|
-
protected colleaguesMap: Map<string, C>;
|
|
9
|
-
constructor(colleagues: ReadonlyArray<C>);
|
|
10
|
-
/**
|
|
11
|
-
*
|
|
12
|
-
*/
|
|
13
|
-
initColleagues(): void;
|
|
14
|
-
/**
|
|
15
|
-
*
|
|
16
|
-
* @param key
|
|
17
|
-
*/
|
|
18
|
-
getColleague(key: string): C;
|
|
19
|
-
}
|