@rotorjs/dashboard 0.4.0 → 0.5.1

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,3 +1,4 @@
1
+ import { TypedEventTarget } from '@rotorjs/state';
1
2
  import { DashboardEventTarget } from './DashboardEventTarget';
2
3
  import { DashboardFact } from './DashboardFact';
3
4
  import { DashboardVar } from './DashboardVar';
@@ -8,11 +9,11 @@ export type DashboardEnvironmentInit = {
8
9
  facts?: {
9
10
  [name: string]: DashboardFact;
10
11
  };
11
- onVar?: (name: string, value: DashboardVar | undefined) => void;
12
- onFact?: (name: string, value: DashboardFact | undefined) => void;
13
- signal?: AbortSignal;
14
12
  };
15
- export declare class DashboardEnvironment {
13
+ export declare class DashboardEnvironment extends TypedEventTarget<{
14
+ var: VarEvent;
15
+ fact: FactEvent;
16
+ }> {
16
17
  #private;
17
18
  constructor(target: DashboardEventTarget, init?: DashboardEnvironmentInit);
18
19
  get target(): DashboardEventTarget;
@@ -26,3 +27,16 @@ export declare class DashboardEnvironment {
26
27
  getFacts(): [name: string, value: DashboardFact][];
27
28
  stop(): void;
28
29
  }
30
+ export declare class VarEvent extends Event {
31
+ #private;
32
+ constructor(name: string, value: unknown, exposed: boolean);
33
+ get name(): string;
34
+ get value(): unknown;
35
+ get exposed(): boolean;
36
+ }
37
+ export declare class FactEvent extends Event {
38
+ #private;
39
+ constructor(name: string, value: unknown);
40
+ get name(): string;
41
+ get value(): unknown;
42
+ }
package/dist/main.d.ts CHANGED
@@ -1,5 +1,6 @@
1
1
  export * from './DashboardAction';
2
2
  export * from './DashboardEngine';
3
+ export * from './DashboardEnvironment';
3
4
  export * from './DashboardEventTarget';
4
5
  export * from './DashboardFact';
5
6
  export * from './DashboardState';
package/dist/main.js CHANGED
@@ -1,32 +1,31 @@
1
- import { ActionEvent as e, StateConsumer as t, StateEngine as n, StateEventTarget as r, StateReducer as i } from "@rotorjs/state";
2
- import a from "fast-deep-equal";
3
- import { v7 as o } from "uuid";
1
+ import { ActionEvent as e, StateConsumer as t, StateEngine as n, StateEventTarget as r, StateReducer as i, TypedEventTarget as a } from "@rotorjs/state";
2
+ import o from "fast-deep-equal";
3
+ import { v7 as s } from "uuid";
4
4
  //#region lib/DashboardEnvironment.ts
5
- var s = class {
5
+ var c = class extends a {
6
6
  #e;
7
- #t = o();
7
+ #t = s();
8
8
  #n;
9
9
  #r;
10
- #i;
11
- #a = new AbortController();
10
+ #i = new AbortController();
12
11
  constructor(t, n) {
13
- this.#e = t, this.#n = Object.fromEntries(Object.entries(n?.vars ?? {}).map(([e, t]) => [e, Object.freeze(t)])), this.#r = Object.fromEntries(Object.entries(n?.facts ?? {}).map(([e, t]) => [e, Object.freeze(t)])), this.#i = n?.signal;
12
+ super(), this.#e = t, this.#n = Object.fromEntries(Object.entries(n?.vars ?? {}).map(([e, t]) => [e, Object.freeze(t)])), this.#r = Object.fromEntries(Object.entries(n?.facts ?? {}).map(([e, t]) => [e, Object.freeze(t)]));
14
13
  let r = this.signal;
15
14
  this.target.addEventListener("action", (t) => {
16
15
  if (t.emitter === this.#t) return;
17
- let r = t.action;
18
- switch (r.type) {
16
+ let n = t.action;
17
+ switch (n.type) {
19
18
  case "var": {
20
- let e = this.#n[r.name], t = Object.freeze({
21
- value: r.value,
22
- exposed: r.exposed ?? !1
19
+ let e = this.#n[n.name], t = Object.freeze({
20
+ value: n.value,
21
+ exposed: n.exposed ?? !1
23
22
  });
24
- a(e, t) || (this.#n[r.name] = t, n?.onVar?.(r.name, t));
23
+ o(e, t) || (this.#n[n.name] = t, this.dispatchEvent(new l(n.name, t.value, t.exposed)));
25
24
  return;
26
25
  }
27
26
  case "fact": {
28
- let e = this.#r[r.name], t = Object.freeze({ value: r.value });
29
- a(e, t) || (this.#r[r.name] = t, n?.onFact?.(r.name, t));
27
+ let e = this.#r[n.name], t = Object.freeze({ value: n.value });
28
+ o(e, t) || (this.#r[n.name] = t, this.dispatchEvent(new u(n.name, t.value)));
30
29
  return;
31
30
  }
32
31
  case "sync": Object.entries(this.#n).forEach(([t, { value: n, exposed: r }]) => {
@@ -55,7 +54,7 @@ var s = class {
55
54
  return this.#t;
56
55
  }
57
56
  get signal() {
58
- return this.#i ? AbortSignal.any([this.#a.signal, this.#i]) : this.#a.signal;
57
+ return this.#i.signal;
59
58
  }
60
59
  hasVar(e) {
61
60
  return Object.hasOwn(this.#n, e);
@@ -76,33 +75,62 @@ var s = class {
76
75
  return Object.entries(this.#r);
77
76
  }
78
77
  stop() {
79
- this.#a.abort();
78
+ this.#i.abort();
79
+ }
80
+ }, l = class extends Event {
81
+ #e;
82
+ #t;
83
+ #n;
84
+ constructor(e, t, n) {
85
+ super("var"), this.#e = e, this.#t = t, this.#n = n;
86
+ }
87
+ get name() {
88
+ return this.#e;
89
+ }
90
+ get value() {
91
+ return this.#t;
92
+ }
93
+ get exposed() {
94
+ return this.#n;
95
+ }
96
+ }, u = class extends Event {
97
+ #e;
98
+ #t;
99
+ constructor(e, t) {
100
+ super("fact"), this.#e = e, this.#t = t;
101
+ }
102
+ get name() {
103
+ return this.#e;
104
+ }
105
+ get value() {
106
+ return this.#t;
80
107
  }
81
108
  };
82
109
  //#endregion
83
110
  //#region lib/interests.ts
84
- function c(e) {
111
+ function d(e) {
85
112
  return `dashboard://var/${encodeURIComponent(e)}`;
86
113
  }
87
- function l(e) {
114
+ function f(e) {
88
115
  return `dashboard://fact/${encodeURIComponent(e)}`;
89
116
  }
90
117
  //#endregion
91
118
  //#region lib/DashboardEngine.ts
92
- var u = class extends n {
119
+ var p = class extends n {
93
120
  #e;
94
121
  #t;
95
122
  constructor(e, t, n) {
96
- super(e), this.#e = t, this.#t = new s(this.target, {
123
+ super(e), this.#e = t, this.#t = new c(this.target, {
97
124
  vars: n?.vars,
98
- facts: n?.facts,
99
- onVar: (e) => {
100
- this.target.dispatchInterest(c(e));
101
- },
102
- onFact: (e) => {
103
- this.target.dispatchInterest(l(e));
104
- },
105
- signal: this.signal
125
+ facts: n?.facts
126
+ });
127
+ let r = this.signal;
128
+ this.#t.addEventListener("var", (e) => {
129
+ this.target.dispatchInterest(d(e.name));
130
+ }, { signal: r }), this.#t.addEventListener("fact", (e) => {
131
+ this.target.dispatchInterest(f(e.name));
132
+ }, { signal: r }), r.addEventListener("abort", () => {
133
+ this.#t.stop();
106
134
  });
107
135
  }
108
136
  hasVar(e) {
@@ -127,7 +155,7 @@ var u = class extends n {
127
155
  createReducer(e) {
128
156
  return this.getReducerConfig(e).createReducer(this, e);
129
157
  }
130
- }, d = class extends r {
158
+ }, m = class extends r {
131
159
  dispatchVar(e, t, n) {
132
160
  this.dispatchAction({
133
161
  type: "var",
@@ -146,7 +174,7 @@ var u = class extends n {
146
174
  sync() {
147
175
  this.dispatchAction({ type: "sync" });
148
176
  }
149
- }, f = class extends t {
177
+ }, h = class extends t {
150
178
  constructor(e, t, n) {
151
179
  super(e, t, n), this.target.addEventListener("action", (e) => {
152
180
  switch (e.action.type) {
@@ -157,20 +185,20 @@ var u = class extends n {
157
185
  }, { signal: this.signal });
158
186
  }
159
187
  compareStates(e, t) {
160
- return a(e, t);
188
+ return o(e, t);
161
189
  }
162
- }, p = class extends i {
190
+ }, g = class extends i {
163
191
  recover(e, t) {
164
192
  return [{
165
193
  type: "error",
166
- id: o(),
194
+ id: s(),
167
195
  error: t
168
196
  }];
169
197
  }
170
198
  compareStates(e, t) {
171
- return a(e, t);
199
+ return o(e, t);
172
200
  }
173
- }, m = "locale", h = class {
201
+ }, _ = "locale", v = class {
174
202
  #e;
175
203
  constructor(e) {
176
204
  this.#e = e ?? {};
@@ -178,19 +206,19 @@ var u = class extends n {
178
206
  getLocale(e) {
179
207
  if (e?.locale) return e.locale;
180
208
  if (this.#e?.locale) return this.#e.locale;
181
- let t = this.#e?.reducer?.engine.getFact(m)?.value;
182
- return this.#e?.reducer?.addInterest(l(m)), typeof t == "string" ? t : void 0;
209
+ let t = this.#e?.reducer?.engine.getFact(_)?.value;
210
+ return this.#e?.reducer?.addInterest(f(_)), typeof t == "string" ? t : void 0;
183
211
  }
184
212
  getFormat(e) {
185
213
  return new Intl.NumberFormat(this.getLocale(e));
186
214
  }
187
215
  format(e, t) {
188
216
  switch (t?.type) {
189
- default: return g(this.getFormat(t).format(e), t);
217
+ default: return y(this.getFormat(t).format(e), t);
190
218
  }
191
219
  }
192
220
  };
193
- function g(e, t) {
221
+ function y(e, t) {
194
222
  let n;
195
223
  if (n = typeof t?.unit == "string" ? t.unit : t?.unit?.value, !n) return e;
196
224
  let r;
@@ -208,4 +236,4 @@ function g(e, t) {
208
236
  }
209
237
  }
210
238
  //#endregion
211
- export { u as DashboardEngine, d as DashboardEventTarget, f as DashboardStateConsumer, p as DashboardStateReducer, h as NumberFormatter, l as dashboardFactInterest, m as dashboardLocaleFact, c as dashboardVarInterest };
239
+ export { p as DashboardEngine, c as DashboardEnvironment, m as DashboardEventTarget, h as DashboardStateConsumer, g as DashboardStateReducer, u as FactEvent, v as NumberFormatter, l as VarEvent, f as dashboardFactInterest, _ as dashboardLocaleFact, d as dashboardVarInterest };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@rotorjs/dashboard",
3
- "version": "0.4.0",
3
+ "version": "0.5.1",
4
4
  "description": "Rotor",
5
5
  "author": {
6
6
  "name": "Aaron Burmeister"