@geosdi/ngx-model 1.2.3 → 2.0.0
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 +79 -13
- package/fesm2022/geosdi-ngx-model.mjs +23 -52
- package/fesm2022/geosdi-ngx-model.mjs.map +1 -1
- package/package.json +4 -3
- package/types/geosdi-ngx-model.d.ts +52 -0
- package/index.d.ts +0 -58
package/README.md
CHANGED
|
@@ -1,24 +1,90 @@
|
|
|
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
|
+
`initColleagues()` is public, but calling it again only re-adds the same array to the map;
|
|
71
|
+
- **two colleagues with the same key**: the last one wins, with no warning;
|
|
72
|
+
- `getColleague` returns `null` for an unknown key;
|
|
73
|
+
- `NgxMediator` is a plain class, not an Angular service: to inject it, provide it yourself (for
|
|
74
|
+
instance with a `useFactory` that receives the colleagues).
|
|
75
|
+
|
|
76
|
+
## Model
|
|
77
|
+
|
|
78
|
+
`Model` is the base interface of an entity: an optional `id`, a string, a number or `null`.
|
|
79
|
+
|
|
80
|
+
## Changes in 2.0.0
|
|
81
|
+
|
|
82
|
+
- **A major version**, released together with the other `@geosdi` libraries rebuilt for Angular 22.
|
|
83
|
+
For this library nothing changes: it has no peer dependencies and its API is the same.
|
|
84
|
+
- Compiled with Angular 22. The library still has no dependencies.
|
|
85
|
+
- This README: `initColleagues()` and the `null` id.
|
|
86
|
+
- The code is unchanged.
|
|
87
|
+
|
|
88
|
+
## Changes in 1.2.4
|
|
89
|
+
|
|
90
|
+
- This README, which replaces the one generated by Angular CLI. The code is unchanged.
|
|
@@ -1,53 +1,24 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
}
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
constructor(colleagues) {
|
|
23
|
-
this.colleagues = colleagues;
|
|
24
|
-
this.colleaguesMap = new Map();
|
|
25
|
-
this.initColleagues();
|
|
26
|
-
}
|
|
27
|
-
/**
|
|
28
|
-
*
|
|
29
|
-
*/
|
|
30
|
-
initColleagues() {
|
|
31
|
-
this.colleagues.forEach((c) => {
|
|
32
|
-
this.colleaguesMap.set(c.getKey(), c);
|
|
33
|
-
});
|
|
34
|
-
}
|
|
35
|
-
/**
|
|
36
|
-
*
|
|
37
|
-
* @param key
|
|
38
|
-
*/
|
|
39
|
-
getColleague(key) {
|
|
40
|
-
return this.colleaguesMap.has(key) ? this.colleaguesMap.get(key) : null;
|
|
41
|
-
}
|
|
42
|
-
}
|
|
43
|
-
|
|
44
|
-
/*
|
|
45
|
-
* Public API Surface of ngx-model
|
|
46
|
-
*/
|
|
47
|
-
|
|
48
|
-
/**
|
|
49
|
-
* Generated bundle index. Do not edit.
|
|
50
|
-
*/
|
|
51
|
-
|
|
1
|
+
var NgxChainHandler = class {
|
|
2
|
+
set successor(_successor) {
|
|
3
|
+
this._successor = _successor;
|
|
4
|
+
}
|
|
5
|
+
};
|
|
6
|
+
var NgxColleague = class {};
|
|
7
|
+
var NgxMediator = class {
|
|
8
|
+
constructor(colleagues) {
|
|
9
|
+
this.colleagues = colleagues;
|
|
10
|
+
this.colleaguesMap = /* @__PURE__ */ new Map();
|
|
11
|
+
this.initColleagues();
|
|
12
|
+
}
|
|
13
|
+
initColleagues() {
|
|
14
|
+
this.colleagues.forEach((c) => {
|
|
15
|
+
this.colleaguesMap.set(c.getKey(), c);
|
|
16
|
+
});
|
|
17
|
+
}
|
|
18
|
+
getColleague(key) {
|
|
19
|
+
return this.colleaguesMap.has(key) ? this.colleaguesMap.get(key) : null;
|
|
20
|
+
}
|
|
21
|
+
};
|
|
52
22
|
export { NgxChainHandler, NgxColleague, NgxMediator };
|
|
53
|
-
|
|
23
|
+
|
|
24
|
+
//# sourceMappingURL=geosdi-ngx-model.mjs.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"geosdi-ngx-model.mjs","sources":["
|
|
1
|
+
{"version":3,"file":"geosdi-ngx-model.mjs","names":[],"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"],"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"],"mappings":"AAIA,IAAsB,kBAAtB,MAAqC;CAMjC,IAAW,UAAU,YAAa;EAC9B,KAAK,aAAa;CACtB;AACH;ACFD,IAAsB,eAAtB,MAAkC,CAKjC;ACVD,IAAa,cAAb,MAAwB;CAGpB,YAAoB,YAA4B;EAA5B,KAAA,aAAA;EAFV,KAAA,gCAAgC,IAAI,IAAG;EAG7C,KAAK,eAAc;CACvB;CAKA,iBAAc;EACV,KAAK,WAAW,SAAS,MAAK;GAC1B,KAAK,cAAc,IAAI,EAAE,OAAM,GAAI,CAAC;EACxC,CAAC;CACL;CAMA,aAAa,KAAW;EACpB,OAAO,KAAK,cAAc,IAAI,GAAG,IAAI,KAAK,cAAc,IAAI,GAAG,IAAI;CACvE;AACH"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@geosdi/ngx-model",
|
|
3
|
-
"version": "
|
|
3
|
+
"version": "2.0.0",
|
|
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,52 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @author Vito Salvia - CNR IMAA geoSDI Group
|
|
3
|
+
* @email vito.salvia@gmail.com
|
|
4
|
+
*/
|
|
5
|
+
export interface Model {
|
|
6
|
+
id?: string | number | null;
|
|
7
|
+
}
|
|
8
|
+
/**
|
|
9
|
+
* @author Vito Salvia - CNR IMAA geoSDI Group
|
|
10
|
+
* @email vito.salvia@gmail.com
|
|
11
|
+
*/
|
|
12
|
+
export declare abstract class NgxChainHandler<B extends NgxChainHandler<B>> {
|
|
13
|
+
protected _successor: B;
|
|
14
|
+
/**
|
|
15
|
+
*
|
|
16
|
+
*/
|
|
17
|
+
set successor(_successor: B);
|
|
18
|
+
}
|
|
19
|
+
/**
|
|
20
|
+
* @author Vito Salvia - CNR IMAA geoSDI Group
|
|
21
|
+
* @email vito.salvia@gmail.com
|
|
22
|
+
*/
|
|
23
|
+
export interface INgxColleague {
|
|
24
|
+
/**
|
|
25
|
+
*
|
|
26
|
+
*/
|
|
27
|
+
getKey(): any;
|
|
28
|
+
}
|
|
29
|
+
export declare abstract class NgxColleague implements INgxColleague {
|
|
30
|
+
/**
|
|
31
|
+
*
|
|
32
|
+
*/
|
|
33
|
+
abstract getKey(): any;
|
|
34
|
+
}
|
|
35
|
+
/**
|
|
36
|
+
* @author Vito Salvia - CNR IMAA geoSDI Group
|
|
37
|
+
* @email vito.salvia@gmail.com
|
|
38
|
+
*/
|
|
39
|
+
export declare class NgxMediator<C extends INgxColleague> {
|
|
40
|
+
private colleagues;
|
|
41
|
+
protected colleaguesMap: Map<string, C>;
|
|
42
|
+
constructor(colleagues: ReadonlyArray<C>);
|
|
43
|
+
/**
|
|
44
|
+
*
|
|
45
|
+
*/
|
|
46
|
+
initColleagues(): void;
|
|
47
|
+
/**
|
|
48
|
+
*
|
|
49
|
+
* @param key
|
|
50
|
+
*/
|
|
51
|
+
getColleague(key: string): C;
|
|
52
|
+
}
|
package/index.d.ts
DELETED
|
@@ -1,58 +0,0 @@
|
|
|
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 };
|