@omegagrid/core 0.10.57 → 0.10.59

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.
@@ -1,7 +1,9 @@
1
1
  import { ComponentFactory, ComponentId } from "../types";
2
2
  export declare class ComponentStore<T extends HTMLElement = HTMLElement> {
3
- readonly factory: ComponentFactory<T>;
4
3
  readonly items: Map<ComponentId, T>;
4
+ private _resolutions;
5
+ private _factory;
6
+ get factory(): ComponentFactory<T>;
5
7
  constructor(factory: ComponentFactory<T>);
6
8
  get(id: ComponentId): Promise<T>;
7
9
  remove(id: ComponentId): this;
@@ -1 +1 @@
1
- {"version":3,"file":"componentStore.d.ts","sourceRoot":"","sources":["../../src/model/componentStore.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,gBAAgB,EAAE,WAAW,EAAE,MAAM,UAAU,CAAC;AAEzD,qBAAa,cAAc,CAAC,CAAC,SAAS,WAAW,GAAG,WAAW;aAIlC,OAAO,EAAE,gBAAgB,CAAC,CAAC,CAAC;IAFxD,SAAgB,KAAK,sBAA6B;gBAEtB,OAAO,EAAE,gBAAgB,CAAC,CAAC,CAAC;IAElD,GAAG,CAAC,EAAE,EAAE,WAAW;IAKzB,MAAM,CAAC,EAAE,EAAE,WAAW;IAKtB,GAAG,CAAC,EAAE,EAAE,WAAW;IAInB,KAAK;IAIL,OAAO,CAAC,QAAQ,EAAE,CAAC,IAAI,EAAE,CAAC,EAAE,EAAE,EAAE,WAAW,KAAK,IAAI;CAKpD"}
1
+ {"version":3,"file":"componentStore.d.ts","sourceRoot":"","sources":["../../src/model/componentStore.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,gBAAgB,EAAE,WAAW,EAAE,MAAM,UAAU,CAAC;AAEzD,qBAAa,cAAc,CAAC,CAAC,SAAS,WAAW,GAAG,WAAW;IAE9D,SAAgB,KAAK,sBAA6B;IAElD,OAAO,CAAC,YAAY,CAAkF;IACtG,OAAO,CAAC,QAAQ,CAAsB;IACtC,IAAI,OAAO,wBAA2B;gBAE1B,OAAO,EAAE,gBAAgB,CAAC,CAAC,CAAC;IA6BlC,GAAG,CAAC,EAAE,EAAE,WAAW;IAKzB,MAAM,CAAC,EAAE,EAAE,WAAW;IAKtB,GAAG,CAAC,EAAE,EAAE,WAAW;IAInB,KAAK;IAIL,OAAO,CAAC,QAAQ,EAAE,CAAC,IAAI,EAAE,CAAC,EAAE,EAAE,EAAE,WAAW,KAAK,IAAI;CAKpD"}
@@ -1,11 +1,38 @@
1
1
  export class ComponentStore {
2
+ get factory() { return this._factory; }
2
3
  constructor(factory) {
3
- this.factory = factory;
4
4
  this.items = new Map();
5
+ this._resolutions = new Map();
6
+ this._factory = (id) => new Promise((resolve, reject) => {
7
+ if (this._resolutions.has(id)) {
8
+ this._resolutions.get(id).push([resolve, reject]);
9
+ return;
10
+ }
11
+ this._resolutions.set(id, [[resolve, reject]]);
12
+ const res = factory(id);
13
+ if (res instanceof Promise) {
14
+ res.then((component) => {
15
+ this.items.set(id, component);
16
+ const resolutions = this._resolutions.get(id) || [];
17
+ resolutions.forEach(([resolve]) => resolve(component));
18
+ this._resolutions.delete(id);
19
+ }).catch((error) => {
20
+ const resolutions = this._resolutions.get(id) || [];
21
+ resolutions.forEach(([, reject]) => reject(error));
22
+ this._resolutions.delete(id);
23
+ });
24
+ }
25
+ else {
26
+ this.items.set(id, res);
27
+ const resolutions = this._resolutions.get(id) || [];
28
+ resolutions.forEach(([resolve]) => resolve(res));
29
+ this._resolutions.delete(id);
30
+ }
31
+ });
5
32
  }
6
33
  async get(id) {
7
34
  if (!this.items.has(id))
8
- this.items.set(id, await this.factory(id));
35
+ this.items.set(id, await this._factory(id));
9
36
  return this.items.get(id);
10
37
  }
11
38
  remove(id) {
@@ -1 +1 @@
1
- {"version":3,"file":"componentStore.js","sourceRoot":"","sources":["../../src/model/componentStore.ts"],"names":[],"mappings":"AAEA,MAAM,OAAO,cAAc;IAI1B,YAA4B,OAA4B;QAA5B,YAAO,GAAP,OAAO,CAAqB;QAFxC,UAAK,GAAG,IAAI,GAAG,EAAkB,CAAC;IAEU,CAAC;IAE7D,KAAK,CAAC,GAAG,CAAC,EAAe;QACxB,IAAI,CAAC,IAAI,CAAC,KAAK,CAAC,GAAG,CAAC,EAAE,CAAC;YAAE,IAAI,CAAC,KAAK,CAAC,GAAG,CAAC,EAAE,EAAE,MAAM,IAAI,CAAC,OAAO,CAAC,EAAE,CAAC,CAAC,CAAC;QACpE,OAAO,IAAI,CAAC,KAAK,CAAC,GAAG,CAAC,EAAE,CAAC,CAAC;IAC3B,CAAC;IAED,MAAM,CAAC,EAAe;QACrB,IAAI,CAAC,KAAK,CAAC,MAAM,CAAC,EAAE,CAAC,CAAC;QACtB,OAAO,IAAI,CAAC;IACb,CAAC;IAED,GAAG,CAAC,EAAe;QAClB,OAAO,IAAI,CAAC,KAAK,CAAC,GAAG,CAAC,EAAE,CAAC,CAAC;IAC3B,CAAC;IAED,KAAK;QACJ,IAAI,CAAC,KAAK,CAAC,KAAK,EAAE,CAAC;IACpB,CAAC;IAED,OAAO,CAAC,QAA4C;QACnD,IAAI,CAAC,KAAK,CAAC,OAAO,CAAC,QAAQ,CAAC,CAAC;QAC7B,OAAO,IAAI,CAAC;IACb,CAAC;CAED","sourcesContent":["import { ComponentFactory, ComponentId } from \"../types\";\n\nexport class ComponentStore<T extends HTMLElement = HTMLElement> {\n\n\tpublic readonly items = new Map<ComponentId, T>();\n\n\tconstructor(public readonly factory: ComponentFactory<T>) { }\n\n\tasync get(id: ComponentId) {\n\t\tif (!this.items.has(id)) this.items.set(id, await this.factory(id));\n\t\treturn this.items.get(id);\n\t}\n\n\tremove(id: ComponentId) {\n\t\tthis.items.delete(id);\n\t\treturn this;\n\t}\n\n\thas(id: ComponentId) {\n\t\treturn this.items.has(id);\n\t}\n\n\tclear() {\n\t\tthis.items.clear();\n\t}\n\n\tforEach(callback: (item: T, id: ComponentId) => void) {\n\t\tthis.items.forEach(callback);\n\t\treturn this;\n\t}\n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AAC,CAAC;IAC3B,CAAC;IAED,KAAK;QACJ,IAAI,CAAC,KAAK,CAAC,KAAK,EAAE,CAAC;IACpB,CAAC;IAED,OAAO,CAAC,QAA4C;QACnD,IAAI,CAAC,KAAK,CAAC,OAAO,CAAC,QAAQ,CAAC,CAAC;QAC7B,OAAO,IAAI,CAAC;IACb,CAAC;CAED","sourcesContent":["import { ComponentFactory, ComponentId } from \"../types\";\n\nexport class ComponentStore<T extends HTMLElement = HTMLElement> {\n\n\tpublic readonly items = new Map<ComponentId, T>();\n\t\n\tprivate _resolutions: Map<ComponentId, [(value: T) => void, (reason: unknown) => void][]> = new Map();\n\tprivate _factory: ComponentFactory<T>;\n\tget factory() { return this._factory }\n\n\tconstructor(factory: ComponentFactory<T>) { \n\t\tthis._factory = (id: ComponentId) => new Promise((resolve, reject) => {\n\t\t\tif (this._resolutions.has(id)) {\n\t\t\t\tthis._resolutions.get(id).push([resolve, reject]);\n\t\t\t\treturn;\n\t\t\t}\n\n\t\t\tthis._resolutions.set(id, [[resolve, reject]]);\n\t\t\tconst res = factory(id);\n\t\t\tif (res instanceof Promise) {\n\t\t\t\tres.then((component) => {\n\t\t\t\t\tthis.items.set(id, component);\n\t\t\t\t\tconst resolutions = this._resolutions.get(id) || [];\n\t\t\t\t\tresolutions.forEach(([resolve]) => resolve(component));\n\t\t\t\t\tthis._resolutions.delete(id);\n\t\t\t\t}).catch((error) => {\n\t\t\t\t\tconst resolutions = this._resolutions.get(id) || [];\n\t\t\t\t\tresolutions.forEach(([, reject]) => reject(error));\n\t\t\t\t\tthis._resolutions.delete(id);\n\t\t\t\t});\n\t\t\t} else {\n\t\t\t\tthis.items.set(id, res);\n\t\t\t\tconst resolutions = this._resolutions.get(id) || [];\n\t\t\t\tresolutions.forEach(([resolve]) => resolve(res));\n\t\t\t\tthis._resolutions.delete(id);\n\t\t\t}\n\t\t});\n\t}\n\n\tasync get(id: ComponentId) {\n\t\tif (!this.items.has(id)) this.items.set(id, await this._factory(id));\n\t\treturn this.items.get(id);\n\t}\n\n\tremove(id: ComponentId) {\n\t\tthis.items.delete(id);\n\t\treturn this;\n\t}\n\n\thas(id: ComponentId) {\n\t\treturn this.items.has(id);\n\t}\n\n\tclear() {\n\t\tthis.items.clear();\n\t}\n\n\tforEach(callback: (item: T, id: ComponentId) => void) {\n\t\tthis.items.forEach(callback);\n\t\treturn this;\n\t}\n\t\n}"]}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@omegagrid/core",
3
- "version": "0.10.57",
3
+ "version": "0.10.59",
4
4
  "license": "UNLICENSED",
5
5
  "description": "Core components",
6
6
  "main": "./dist/index.js",
@@ -36,7 +36,7 @@
36
36
  },
37
37
  "dependencies": {
38
38
  "@fortawesome/fontawesome-svg-core": "^7.0.1",
39
- "@omegagrid/localize": "^0.10.57",
39
+ "@omegagrid/localize": "^0.10.59",
40
40
  "color": "^4.2.3",
41
41
  "date-fns": "^3.2.0",
42
42
  "lit": "^3.1.1",