@panyam/tsutils 0.0.63 → 0.0.65
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/lib/cjs/comms/events.d.ts +6 -4
- package/lib/cjs/comms/events.js +26 -11
- package/lib/cjs/comms/events.js.map +1 -1
- package/lib/cjs/index.js.map +1 -1
- package/lib/cjs/numberutils.js.map +1 -1
- package/lib/esm/comms/events.d.ts +6 -4
- package/lib/esm/comms/events.js +26 -11
- package/lib/esm/comms/events.js.map +1 -1
- package/lib/esm/index.js.map +1 -1
- package/lib/esm/numberutils.js.map +1 -1
- package/package.json +1 -1
- package/lib/cjs/properties.d.ts +0 -54
- package/lib/cjs/properties.js +0 -158
- package/lib/cjs/properties.js.map +0 -1
- package/lib/esm/properties.d.ts +0 -54
- package/lib/esm/properties.js +0 -149
- package/lib/esm/properties.js.map +0 -1
|
@@ -35,10 +35,6 @@ export declare class EventEmitter {
|
|
|
35
35
|
}
|
|
36
36
|
export declare class EventHub {
|
|
37
37
|
private _handlers;
|
|
38
|
-
private _muted;
|
|
39
|
-
get isMuted(): boolean;
|
|
40
|
-
mute(): void;
|
|
41
|
-
unmute(): void;
|
|
42
38
|
on(names: Array<string> | string, callback: EventCallback): this;
|
|
43
39
|
removeOn(names: Array<string> | string, callback: EventCallback): this;
|
|
44
40
|
_ensurestrings(names: Array<string> | string): string[];
|
|
@@ -50,6 +46,12 @@ export declare class EventHub {
|
|
|
50
46
|
}, handler: T): this;
|
|
51
47
|
emit(name: string, source: any, payload?: any): boolean;
|
|
52
48
|
dispatchEvent(event: TEvent): boolean;
|
|
49
|
+
static BATCH_EVENTS: string;
|
|
50
|
+
protected _events: TEvent[];
|
|
51
|
+
protected _inBatchMode: boolean;
|
|
52
|
+
startBatchMode(): this;
|
|
53
|
+
cancelBatch(): void;
|
|
54
|
+
commitBatch(): void;
|
|
53
55
|
}
|
|
54
56
|
export declare class StateMachine {
|
|
55
57
|
private _states;
|
package/lib/cjs/comms/events.js
CHANGED
|
@@ -71,16 +71,8 @@ exports.EventEmitter = EventEmitter;
|
|
|
71
71
|
class EventHub {
|
|
72
72
|
constructor() {
|
|
73
73
|
this._handlers = {};
|
|
74
|
-
this.
|
|
75
|
-
|
|
76
|
-
get isMuted() {
|
|
77
|
-
return this._muted;
|
|
78
|
-
}
|
|
79
|
-
mute() {
|
|
80
|
-
this._muted = true;
|
|
81
|
-
}
|
|
82
|
-
unmute() {
|
|
83
|
-
this._muted = false;
|
|
74
|
+
this._events = [];
|
|
75
|
+
this._inBatchMode = false;
|
|
84
76
|
}
|
|
85
77
|
on(names, callback) {
|
|
86
78
|
return this._addHandler(names, this._handlers, callback);
|
|
@@ -116,7 +108,14 @@ class EventHub {
|
|
|
116
108
|
return this;
|
|
117
109
|
}
|
|
118
110
|
emit(name, source, payload) {
|
|
119
|
-
|
|
111
|
+
const evt = new TEvent(name, source, payload);
|
|
112
|
+
if (this._inBatchMode) {
|
|
113
|
+
this._events.push(evt);
|
|
114
|
+
return true;
|
|
115
|
+
}
|
|
116
|
+
else {
|
|
117
|
+
return this.dispatchEvent(evt);
|
|
118
|
+
}
|
|
120
119
|
}
|
|
121
120
|
dispatchEvent(event) {
|
|
122
121
|
const evtCallbacks = this._handlers[event.name] || [];
|
|
@@ -127,8 +126,24 @@ class EventHub {
|
|
|
127
126
|
}
|
|
128
127
|
return true;
|
|
129
128
|
}
|
|
129
|
+
startBatchMode() {
|
|
130
|
+
if (!this._inBatchMode) {
|
|
131
|
+
this._inBatchMode = true;
|
|
132
|
+
}
|
|
133
|
+
return this;
|
|
134
|
+
}
|
|
135
|
+
cancelBatch() {
|
|
136
|
+
this._inBatchMode = false;
|
|
137
|
+
this._events = [];
|
|
138
|
+
}
|
|
139
|
+
commitBatch() {
|
|
140
|
+
this._inBatchMode = false;
|
|
141
|
+
this.emit(EventHub.BATCH_EVENTS, this, this._events);
|
|
142
|
+
this._events = [];
|
|
143
|
+
}
|
|
130
144
|
}
|
|
131
145
|
exports.EventHub = EventHub;
|
|
146
|
+
EventHub.BATCH_EVENTS = "BatchEvents";
|
|
132
147
|
class StateMachine {
|
|
133
148
|
constructor() {
|
|
134
149
|
this._states = {};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"events.js","sourceRoot":"","sources":["../../../src/comms/events.ts"],"names":[],"mappings":";;;AAKA,MAAa,MAAM;IAiDjB,YAAY,IAAY,EAAE,MAAW,EAAE,OAAa;QA9C3C,SAAI,GAAG,MAAM,CAAC,OAAO,EAAE,CAAC;QAKvB,iBAAY,GAAmB,IAAI,CAAC;QAgB9C,gBAAW,GAAQ,IAAI,CAAC;QAUxB,cAAS,GAAG,KAAK,CAAC;QAKlB,cAAS,GAAc,CAAC,CAAC,CAAC;QAQ1B,aAAQ,GAAa,EAAE,CAAC;QAGtB,IAAI,CAAC,IAAI,GAAG,IAAI,CAAC;QACjB,IAAI,CAAC,MAAM,GAAG,MAAM,CAAC;QACrB,IAAI,CAAC,OAAO,GAAG,OAAO,CAAC;IACzB,CAAC;IAED,IAAI,WAAW;QACb,OAAO,IAAI,CAAC,YAAY,CAAC;IAC3B,CAAC;IAES,cAAc,CAAC,GAAmB;QAC1C,IAAI,CAAC,YAAY,GAAG,GAAG,CAAC;QACxB,IAAI,GAAG,IAAI,IAAI;YAAE,IAAI,CAAC,UAAU,GAAG,IAAI,CAAC;;YACnC,IAAI,CAAC,UAAU,GAAG,GAAG,CAAC,SAAS,CAAC;IACvC,CAAC;IAED,KAAK,CAAC,IAAY,EAAE,MAAW,EAAE,OAAa;QAC5C,MAAM,KAAK,GAAG,IAAI,MAAM,CAAC,IAAI,EAAE,MAAM,EAAE,OAAO,CAAC,CAAC;QAChD,KAAK,CAAC,cAAc,CAAC,IAAI,CAAC,CAAC;QAC3B,IAAI,CAAC,QAAQ,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC;QAC1B,OAAO,KAAK,CAAC;IACf,CAAC;IAOD,IAAI,SAAS;QACX,OAAO,IAAI,CAAC,U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iBAAM;gBACL,IAAI,CAAC,KAAK,CAAC,SAAS,CAAC,CAAC;aACvB;SACF;IACH,CAAC;CACF;AA7FD,oCA6FC","sourcesContent":["import { Nullable, Timestamp } from \"../types\";\n\n/**\n * Super class of all Events.\n */\nexport class TEvent {\n // Globally unique ID for all events.\n private static counter = 0;\n readonly uuid = TEvent.counter++;\n\n /**\n * The event this event was spawned from (if any).\n */\n protected _spawnedFrom: Nullable<this> = null;\n\n /**\n * Name of the event.\n */\n readonly name: string;\n\n /**\n * Source from which this event is originating.\n */\n readonly source: any;\n\n /**\n * Source state that is set by the source of the event only\n * *it* can use.\n */\n sourceState: any = null;\n\n /**\n * Event specific payload.\n */\n payload: any;\n\n /**\n * Whether the event was cancelled.\n */\n cancelled = false;\n\n /**\n * Timestamp of the event - optional.\n */\n timeStamp: Timestamp = -1;\n\n /**\n * All child events that were spawned from this Event.\n * The parent/spawnedFrom and child event references help us\n * form a call tree/trace of a events as it traverses\n * the system.\n */\n children: TEvent[] = [];\n\n constructor(name: string, source: any, payload?: any) {\n this.name = name;\n this.source = source;\n this.payload = payload;\n }\n\n get spawnedFrom(): Nullable<this> {\n return this._spawnedFrom;\n }\n\n protected setSpawnedFrom(msg: Nullable<this>): void {\n this._spawnedFrom = msg;\n if (msg == null) this._rootEvent = this;\n else this._rootEvent = msg.rootEvent;\n }\n\n spawn(name: string, source: any, payload?: any): TEvent {\n const child = new TEvent(name, source, payload);\n child.setSpawnedFrom(this);\n this.children.push(child);\n return child;\n }\n\n /**\n * The first/root message in the forward chain.\n */\n private _rootEvent: this;\n\n get rootEvent(): this {\n return this._rootEvent as this;\n }\n}\n\nexport class State {\n private static counter = 0;\n stateData: any = null;\n readonly id = State.counter++;\n\n get name(): string {\n return this.constructor.name;\n }\n\n enter(data: any): void {\n this.stateData = data;\n }\n\n handle(event: TEvent): void {\n // todo\n }\n}\n\nexport type EventCallback = ((event: TEvent) => void) | ((event: TEvent) => Promise<void>);\n\nexport class EventEmitter {\n protected _eventHub: EventHub | null;\n constructor() {\n this._eventHub = new EventHub();\n }\n get eventHub(): EventHub | null {\n return this._eventHub;\n }\n set eventHub(hub: EventHub | null) {\n const oldHub = this._eventHub;\n this._eventHub = hub;\n this.eventHubChanged(oldHub);\n }\n protected eventHubChanged(oldHub: EventHub | null): void {\n // Do nothing\n console.log(\"WARNING - EventHub Change Listener not implemented: \", this.constructor.name);\n }\n}\n\nexport class EventHub {\n private _handlers: { [key: string]: Array<EventCallback> } = {};\n private _muted = false;\n\n get isMuted(): boolean {\n return this._muted;\n }\n\n mute(): void {\n this._muted = true;\n }\n\n unmute(): void {\n this._muted = false;\n }\n\n on(names: Array<string> | string, callback: EventCallback): this {\n return this._addHandler(names, this._handlers, callback);\n }\n\n removeOn(names: Array<string> | string, callback: EventCallback): this {\n return this._removeHandler(names, this._handlers, callback);\n }\n\n _ensurestrings(names: Array<string> | string): string[] {\n if (typeof names === \"string\") {\n names = (names as string).split(\",\");\n }\n return names.map(function (v) {\n return v.trim();\n });\n }\n\n _addHandler<T>(names: Array<string> | string, handlerlist: { [key: string]: Array<T> }, handler: T): this {\n this._ensurestrings(names).forEach(function (name) {\n handlerlist[name] = handlerlist[name] || [];\n handlerlist[name].push(handler);\n });\n return this;\n }\n\n _removeHandler<T>(names: Array<string> | string, handlerlist: { [key: string]: Array<T> }, handler: T): this {\n this._ensurestrings(names).forEach(function (name) {\n const evHandlers = handlerlist[name] || [];\n for (let i = 0; i < evHandlers.length; i++) {\n if (evHandlers[i] == handler) {\n evHandlers.splice(i, 1);\n break;\n }\n }\n });\n return this;\n }\n\n emit(name: string, source: any, payload?: any): boolean {\n return this.dispatchEvent(new TEvent(name, source, payload));\n }\n\n dispatchEvent(event: TEvent): boolean {\n const evtCallbacks = this._handlers[event.name] || [];\n for (const callback of evtCallbacks) {\n callback(event);\n if (event.cancelled) return false;\n }\n return true;\n }\n}\n\n/**\n * StateMachines allow declarative and stateful chaining of events.\n */\nexport class StateMachine {\n private _states: { [key: string]: State } = {};\n private _rootState: Nullable<State> = null;\n private _currentState: Nullable<State> = null;\n constructor() {\n this._states = {};\n this._rootState = null;\n this._currentState = null;\n }\n\n /**\n * The starting/root state of the machine.\n *\n * @param {String} name Name of the default/root state.\n */\n set rootState(name: string) {\n this._rootState = this.getState(name);\n if (this._currentState == null) {\n this._currentState = this._rootState;\n }\n }\n\n /**\n * Exits the current state (if any) and enters a new state.\n *\n * @param {String} state Name of the new state to enter.\n * @param {Object} data State specific data for the state handler to use for the new state.\n */\n enter(state: string, data: any = null): void {\n if (state == \"\") {\n this._currentState = this._rootState;\n } else {\n this._currentState = this.getState(state);\n }\n if (this._currentState != null) {\n this._currentState.enter(data);\n }\n }\n\n /**\n * Get the state by name.\n *\n * @param {String} name Name of the state being queried.\n * @returns {State} State object associated with the name.\n */\n getState(name: string): State {\n if (!(name in this._states)) {\n throw Error(\"State '\" + name + \"' not yet registered.\");\n }\n return this._states[name];\n }\n\n /**\n * Register a new state in the state machine.\n *\n * @param {State} state State being registered. If another State with\n * the same name exists, then a {DuplicateError} is thrown.\n * @param {Bool} isRoot Whether the new state is a root state.\n */\n registerState(state: State, isRoot = false): void {\n const name = state.name;\n if (name in this._states) {\n throw Error(\"State '\" + name + \"' already registered.\");\n }\n this._states[name] = state;\n if (isRoot || false) {\n this.rootState = state.name;\n }\n }\n\n /**\n * Handles an event from the current state in the state machine possibly resulting in a state transition.\n *\n * @param {Object} name Type of event being sent.\n * @param {EventSource} source The source generating the event.\n * @param {Object} data The event specific data.\n */\n handle(event: TEvent): void {\n if (this._currentState == null) return;\n\n const nextState: any = this._currentState.handle(event);\n if (nextState != null) {\n if (nextState == \"\") {\n if (this._rootState != null) {\n this.enter(this._rootState.name);\n } else {\n throw new Error(\"Root state has not been set\");\n }\n } else {\n this.enter(nextState);\n }\n }\n }\n}\n"]}
|
|
1
|
+
{"version":3,"file":"events.js","sourceRoot":"","sources":["../../../src/comms/events.ts"],"names":[],"mappings":";;;AAKA,MAAa,MAAM;IAiDjB,YAAY,IAA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AE;YACrB,IAAI,SAAS,IAAI,EAAE,EAAE;gBACnB,IAAI,IAAI,CAAC,UAAU,IAAI,IAAI,EAAE;oBAC3B,IAAI,CAAC,KAAK,CAAC,IAAI,CAAC,UAAU,CAAC,IAAI,CAAC,CAAC;iBAClC;qBAAM;oBACL,MAAM,IAAI,KAAK,CAAC,6BAA6B,CAAC,CAAC;iBAChD;aACF;iBAAM;gBACL,IAAI,CAAC,KAAK,CAAC,SAAS,CAAC,CAAC;aACvB;SACF;IACH,CAAC;CACF;AA7FD,oCA6FC","sourcesContent":["import { Nullable, Timestamp } from \"../types\";\n\n/**\n * Super class of all Events.\n */\nexport class TEvent {\n // Globally unique ID for all events.\n private static counter = 0;\n readonly uuid = TEvent.counter++;\n\n /**\n * The event this event was spawned from (if any).\n */\n protected _spawnedFrom: Nullable<this> = null;\n\n /**\n * Name of the event.\n */\n readonly name: string;\n\n /**\n * Source from which this event is originating.\n */\n readonly source: any;\n\n /**\n * Source state that is set by the source of the event only\n * *it* can use.\n */\n sourceState: any = null;\n\n /**\n * Event specific payload.\n */\n payload: any;\n\n /**\n * Whether the event was cancelled.\n */\n cancelled = false;\n\n /**\n * Timestamp of the event - optional.\n */\n timeStamp: Timestamp = -1;\n\n /**\n * All child events that were spawned from this Event.\n * The parent/spawnedFrom and child event references help us\n * form a call tree/trace of a events as it traverses\n * the system.\n */\n children: TEvent[] = [];\n\n constructor(name: string, source: any, payload?: any) {\n this.name = name;\n this.source = source;\n this.payload = payload;\n }\n\n get spawnedFrom(): Nullable<this> {\n return this._spawnedFrom;\n }\n\n protected setSpawnedFrom(msg: Nullable<this>): void {\n this._spawnedFrom = msg;\n if (msg == null) this._rootEvent = this;\n else this._rootEvent = msg.rootEvent;\n }\n\n spawn(name: string, source: any, payload?: any): TEvent {\n const child = new TEvent(name, source, payload);\n child.setSpawnedFrom(this);\n this.children.push(child);\n return child;\n }\n\n /**\n * The first/root message in the forward chain.\n */\n private _rootEvent: this;\n\n get rootEvent(): this {\n return this._rootEvent as this;\n }\n}\n\nexport class State {\n private static counter = 0;\n stateData: any = null;\n readonly id = State.counter++;\n\n get name(): string {\n return this.constructor.name;\n }\n\n enter(data: any): void {\n this.stateData = data;\n }\n\n handle(event: TEvent): void {\n // todo\n }\n}\n\nexport type EventCallback = ((event: TEvent) => void) | ((event: TEvent) => Promise<void>);\n\nexport class EventEmitter {\n protected _eventHub: EventHub | null;\n constructor() {\n this._eventHub = new EventHub();\n }\n get eventHub(): EventHub | null {\n return this._eventHub;\n }\n set eventHub(hub: EventHub | null) {\n const oldHub = this._eventHub;\n this._eventHub = hub;\n this.eventHubChanged(oldHub);\n }\n protected eventHubChanged(oldHub: EventHub | null): void {\n // Do nothing\n console.log(\"WARNING - EventHub Change Listener not implemented: \", this.constructor.name);\n }\n}\n\nexport class EventHub {\n private _handlers: { [key: string]: Array<EventCallback> } = {};\n\n on(names: Array<string> | string, callback: EventCallback): this {\n return this._addHandler(names, this._handlers, callback);\n }\n\n removeOn(names: Array<string> | string, callback: EventCallback): this {\n return this._removeHandler(names, this._handlers, callback);\n }\n\n _ensurestrings(names: Array<string> | string): string[] {\n if (typeof names === \"string\") {\n names = (names as string).split(\",\");\n }\n return names.map(function (v) {\n return v.trim();\n });\n }\n\n _addHandler<T>(names: Array<string> | string, handlerlist: { [key: string]: Array<T> }, handler: T): this {\n this._ensurestrings(names).forEach(function (name) {\n handlerlist[name] = handlerlist[name] || [];\n handlerlist[name].push(handler);\n });\n return this;\n }\n\n _removeHandler<T>(names: Array<string> | string, handlerlist: { [key: string]: Array<T> }, handler: T): this {\n this._ensurestrings(names).forEach(function (name) {\n const evHandlers = handlerlist[name] || [];\n for (let i = 0; i < evHandlers.length; i++) {\n if (evHandlers[i] == handler) {\n evHandlers.splice(i, 1);\n break;\n }\n }\n });\n return this;\n }\n\n emit(name: string, source: any, payload?: any): boolean {\n const evt = new TEvent(name, source, payload);\n if (this._inBatchMode) {\n this._events.push(evt);\n return true;\n } else {\n return this.dispatchEvent(evt);\n }\n }\n\n dispatchEvent(event: TEvent): boolean {\n const evtCallbacks = this._handlers[event.name] || [];\n for (const callback of evtCallbacks) {\n callback(event);\n if (event.cancelled) return false;\n }\n return true;\n }\n\n // Support for transactional/batch event handling, where\n // the user can allow a bunch of events to first collect\n // before triggering a batch dispatch\n public static BATCH_EVENTS = \"BatchEvents\";\n protected _events: TEvent[] = [];\n protected _inBatchMode = false;\n startBatchMode(): this {\n if (!this._inBatchMode) {\n this._inBatchMode = true;\n }\n return this;\n }\n\n cancelBatch(): void {\n this._inBatchMode = false;\n this._events = [];\n }\n\n commitBatch(): void {\n this._inBatchMode = false;\n this.emit(EventHub.BATCH_EVENTS, this, this._events);\n this._events = [];\n }\n}\n\n/**\n * StateMachines allow declarative and stateful chaining of events.\n */\nexport class StateMachine {\n private _states: { [key: string]: State } = {};\n private _rootState: Nullable<State> = null;\n private _currentState: Nullable<State> = null;\n constructor() {\n this._states = {};\n this._rootState = null;\n this._currentState = null;\n }\n\n /**\n * The starting/root state of the machine.\n *\n * @param {String} name Name of the default/root state.\n */\n set rootState(name: string) {\n this._rootState = this.getState(name);\n if (this._currentState == null) {\n this._currentState = this._rootState;\n }\n }\n\n /**\n * Exits the current state (if any) and enters a new state.\n *\n * @param {String} state Name of the new state to enter.\n * @param {Object} data State specific data for the state handler to use for the new state.\n */\n enter(state: string, data: any = null): void {\n if (state == \"\") {\n this._currentState = this._rootState;\n } else {\n this._currentState = this.getState(state);\n }\n if (this._currentState != null) {\n this._currentState.enter(data);\n }\n }\n\n /**\n * Get the state by name.\n *\n * @param {String} name Name of the state being queried.\n * @returns {State} State object associated with the name.\n */\n getState(name: string): State {\n if (!(name in this._states)) {\n throw Error(\"State '\" + name + \"' not yet registered.\");\n }\n return this._states[name];\n }\n\n /**\n * Register a new state in the state machine.\n *\n * @param {State} state State being registered. If another State with\n * the same name exists, then a {DuplicateError} is thrown.\n * @param {Bool} isRoot Whether the new state is a root state.\n */\n registerState(state: State, isRoot = false): void {\n const name = state.name;\n if (name in this._states) {\n throw Error(\"State '\" + name + \"' already registered.\");\n }\n this._states[name] = state;\n if (isRoot || false) {\n this.rootState = state.name;\n }\n }\n\n /**\n * Handles an event from the current state in the state machine possibly resulting in a state transition.\n *\n * @param {Object} name Type of event being sent.\n * @param {EventSource} source The source generating the event.\n * @param {Object} data The event specific data.\n */\n handle(event: TEvent): void {\n if (this._currentState == null) return;\n\n const nextState: any = this._currentState.handle(event);\n if (nextState != null) {\n if (nextState == \"\") {\n if (this._rootState != null) {\n this.enter(this._rootState.name);\n } else {\n throw new Error(\"Root state has not been set\");\n }\n } else {\n this.enter(nextState);\n }\n }\n }\n}\n"]}
|
package/lib/cjs/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;AAAA,0CAAwB;AACxB,oDAAoC;AACpC,yDAAyC;AACzC,yDAAyC;AACzC,gDAAgC;AAChC,+CAA+B;AAC/B,qDAAqC;AACrC,6CAA6B;AAC7B,+CAA+B;AAC/B,qDAAqC;AACrC,oDAAoC;
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;AAAA,0CAAwB;AACxB,oDAAoC;AACpC,yDAAyC;AACzC,yDAAyC;AACzC,gDAAgC;AAChC,+CAA+B;AAC/B,qDAAqC;AACrC,6CAA6B;AAC7B,+CAA+B;AAC/B,qDAAqC;AACrC,oDAAoC;AACpC,6CAA6B;AAC7B,qCAAoC;AAA3B,kGAAA,OAAO,OAAA","sourcesContent":["export * from \"./types\";\nexport * as Api from \"./apis/index\";\nexport * as Constants from \"./constants\";\nexport * as Events from \"./comms/events\";\nexport * as Lists from \"./list\";\nexport * as Misc from \"./misc\";\nexport * as Streams from \"./streams\";\nexport * as DOM from \"./dom\";\nexport * as Geom from \"./geom\";\nexport * as Num from \"./numberutils\";\nexport * as Time from \"./timeutils\";\nexport * as DAL from \"./dal\";\nexport { Browser } from \"./browser\";\n"]}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"numberutils.js","sourceRoot":"","sources":["../../src/numberutils.ts"],"names":[],"mappings":";;;AAEA,SAAgB,KAAK,CAAC,KAAa,EAAE,MAAwB,IAAI,EAAE,OAAyB,CAAC;IAC3F,IAAI,GAAG,IAAI,IAAI,EAAE;QACf,MAAM,QAAQ,GAAG,IAAI,CAAC,GAAG,CAAC,KAAK,CAAC,CAAC;QACjC,MAAM,GAAG,GAAG,KAAK,CAAC,IAAI,CAAC,EAAE,MAAM,EAAE,QAAQ,EAAE,CAAC,CAAC;QAC7C,IAAI,KAAK,IAAI,CAAC,EAAE;YACd,OAAO,GAAG,CAAC,GAAG,CAAC,CAAC,CAAC,EAAE,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,CAAC;SAC7B;aAAM;YACL,OAAO,GAAG,CAAC,GAAG,CAAC,CAAC,CAAC,EAAE,CAAC,EAAE,EAAE,CAAC,CAAC,GAAG,CAAC,QAAQ,GAAG,CAAC,CAAC,CAAC,CAAC;SAC9C;KACF;IACD,MAAM,GAAG,GAAa,EAAE,CAAC;IACzB,IAAI,IAAI,IAAI,IAAI,EAAE;QAChB,IAAI,GAAG,CAAC,CAAC;KACV;IACD,IAAI,GAAG,IAAI,CAAC,GAAG,CAAC,IAAI,CAAC,CAAC;IACtB,IAAI,KAAK,KAAK,GAAG,EAAE;QACjB,IAAI,KAAK,GAAG,GAAG,EAAE;YACf,KAAK,IAAI,CAAC,GAAG,KAAK,EAAE,CAAC,IAAI,GAAG,EAAE,CAAC,IAAI,IAAI,EAAE;gBACvC,GAAG,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC;aACb;SACF;aAAM;YACL,KAAK,IAAI,CAAC,GAAG,KAAK,EAAE,CAAC,IAAI,GAAG,EAAE,CAAC,IAAI,IAAI,EAAE;gBACvC,GAAG,CAAC,IAA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MH,4BA4MC;AAxMiB,aAAI,GAAG,IAAI,QAAQ,EAAE,CAAC;AACtB,YAAG,GAAG,IAAI,QAAQ,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC;AACzB,iBAAQ,GAAG,IAAI,QAAQ,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC;AAyMzC,MAAM,IAAI,GAAG,CAAC,CAAC,GAAG,CAAC,EAAE,CAAC,GAAG,CAAC,EAAE,UAAU,GAAG,KAAK,EAAY,EAAE,CAAC,IAAI,QAAQ,CAAC,CAAC,EAAE,CAAC,EAAE,UAAU,CAAC,CAAC;AAAtF,QAAA,IAAI,QAAkF","sourcesContent":["import { Nullable } from \"./types\";\n\nexport function range(start: number, end: Nullable<number> = null, incr: Nullable<number> = 1): number[] {\n if (end == null) {\n const absStart = Math.abs(start);\n const arr = Array.from({ length: absStart });\n if (start >= 0) {\n return arr.map((x, i) => i);\n } else {\n return arr.map((x, i) => i - (absStart - 1));\n }\n }\n const out: number[] = [];\n if (incr == null) {\n incr = 1;\n }\n incr = Math.abs(incr);\n if (start !== end) {\n if (start < end) {\n for (let i = start; i <= end; i += incr) {\n out.push(i);\n }\n } else {\n for (let i = start; i >= end; i -= incr) {\n out.push(i);\n }\n }\n }\n return out;\n}\n\n/*\nexport function applyMixins(derivedCtor: any, baseCtors: any[]) {\n baseCtors.forEach(baseCtor => {\n Object.getOwnPropertyNames(baseCtor.prototype).forEach(name => {\n Object.defineProperty(derivedCtor.prototype, name,\n Object.getOwnPropertyDescriptor(baseCtor.prototype, name));\n });\n });\n}\n*/\n\nexport function gcdof(x: number, y: number): number {\n x = Math.abs(x);\n y = Math.abs(y);\n while (y > 0) {\n const t = y;\n y = x % y;\n x = t;\n }\n return x;\n}\n\nexport class Fraction {\n readonly num: number;\n readonly den: number;\n\n static readonly ZERO = new Fraction();\n static readonly ONE = new Fraction(1, 1);\n static readonly INFINITY = new Fraction(1, 0);\n\n constructor(num = 0, den = 1, factorized = false) {\n if (isNaN(num) || isNaN(den)) {\n throw new Error(`Invalid numerator(${num}) or denminator(${den})`);\n }\n if (factorized) {\n const gcd = gcdof(num, den);\n num /= gcd;\n den /= gcd;\n }\n this.num = num;\n this.den = den;\n }\n\n static parse(val: string, factorized = false): Fraction {\n const parts = val\n .trim()\n .split(\"/\")\n .map((x) => x.trim());\n let num = 1;\n let den = 1;\n if (parts.length == 1) num = parseInt(parts[0]);\n else if (parts.length != 2) {\n throw new Error(\"Invalid fraction string: \" + val);\n } else {\n if (parts[0].length > 0) {\n num = parseInt(parts[0]);\n }\n if (parts[1].length > 0) {\n den = parseInt(parts[1]);\n }\n }\n if (isNaN(num) || isNaN(den)) {\n throw new Error(\"Invalid fraction string: \" + val);\n }\n return new Fraction(num, den, factorized);\n }\n\n get isWhole(): boolean {\n return this.num % this.den == 0;\n }\n\n get isZero(): boolean {\n return this.num == 0;\n }\n\n get isInfinity(): boolean {\n return this.den == 0;\n }\n\n get isOne(): boolean {\n return this.num == this.den;\n }\n\n get ceil(): number {\n if (this.num % this.den == 0) {\n return this.num / this.den;\n } else {\n return 1 + Math.floor(this.num / this.den);\n }\n }\n\n get floor(): number {\n if (this.num % this.den == 0) {\n return this.num / this.den;\n } else {\n return Math.floor(this.num / this.den);\n }\n }\n\n plus(another: Fraction, factorized = false): Fraction {\n return new Fraction(this.num * another.den + this.den * another.num, this.den * another.den, factorized);\n }\n\n plusNum(another: number, factorized = false): Fraction {\n return new Fraction(this.num + this.den * another, this.den, factorized);\n }\n\n minus(another: Fraction, factorized = false): Fraction {\n return new Fraction(this.num * another.den - this.den * another.num, this.den * another.den, factorized);\n }\n\n minusNum(another: number, factorized = false): Fraction {\n return new Fraction(this.num - this.den * another, this.den, factorized);\n }\n\n times(another: Fraction, factorized = false): Fraction {\n return new Fraction(this.num * another.num, this.den * another.den, factorized);\n }\n\n timesNum(another: number, factorized = false): Fraction {\n return new Fraction(this.num * another, this.den, factorized);\n }\n\n divby(another: Fraction, factorized = false): Fraction {\n return new Fraction(this.num * another.den, this.den * another.num, factorized);\n }\n\n divbyNum(another: number, factorized = false): Fraction {\n return new Fraction(this.num, this.den * another, factorized);\n }\n\n /**\n * Returns another / this.\n */\n numDivby(another: number, factorized = false): Fraction {\n return new Fraction(this.den * another, this.num, factorized);\n }\n\n /**\n * Returns this % another\n */\n mod(another: Fraction): Fraction {\n // a (mod b) = a − b ⌊a / b⌋\n const d = this.divby(another);\n const floorOfD = Math.floor(d.num / d.den);\n return this.minus(another.timesNum(floorOfD));\n }\n\n /*\n * Returns this % another\n */\n modNum(another: number): Fraction {\n // a (mod b) = a − b ⌊a / b⌋\n const d = this.divbyNum(another);\n const floorOfD = Math.floor(d.num / d.den);\n return this.minusNum(another * floorOfD);\n }\n\n get inverse(): Fraction {\n return new Fraction(this.den, this.num);\n }\n\n get factorized(): Fraction {\n const gcd = gcdof(this.num, this.den);\n return new Fraction(this.num / gcd, this.den / gcd);\n }\n\n equals(another: Fraction): boolean {\n return this.num * another.den == this.den * another.num;\n }\n\n equalsNum(another: number): boolean {\n return this.num == this.den * another;\n }\n\n cmp(another: Fraction): number {\n return this.num * another.den - this.den * another.num;\n }\n\n cmpNum(another: number): number {\n return this.num - this.den * another;\n }\n\n isLT(another: Fraction): boolean {\n return this.cmp(another) < 0;\n }\n\n isLTE(another: Fraction): boolean {\n return this.cmp(another) <= 0;\n }\n\n isLTNum(another: number): boolean {\n return this.cmpNum(another) < 0;\n }\n\n isLTENum(another: number): boolean {\n return this.cmpNum(another) <= 0;\n }\n\n isGT(another: Fraction): boolean {\n return this.cmp(another) > 0;\n }\n\n isGTE(another: Fraction): boolean {\n return this.cmp(another) >= 0;\n }\n\n isGTNum(another: number): boolean {\n return this.cmpNum(another) > 0;\n }\n\n isGTENum(another: number): boolean {\n return this.cmpNum(another) >= 0;\n }\n\n toString(): string {\n return this.num + \"/\" + this.den;\n }\n\n static max(f1: Fraction, f2: Fraction): Fraction {\n return f1.cmp(f2) > 0 ? f1 : f2;\n }\n\n static min(f1: Fraction, f2: Fraction): Fraction {\n return f1.cmp(f2) < 0 ? f1 : f2;\n }\n}\n\n// Shortcut helper\nexport const Frac = (a = 0, b = 1, factorized = false): Fraction => new Fraction(a, b, factorized);\n"]}
|
|
1
|
+
{"version":3,"file":"numberutils.js","sourceRoot":"","sources":["../../src/numberutils.ts"],"names":[],"mappings":";;;AAEA,SAAgB,KAAK,CAAC,KAAa,EAAE,MAAwB,IAAI,EAAE,OAAyB,CAAC;IAC3F,IAAI,GAAG,IAAI,IAAI,EAAE;QACf,MAAM,QAAQ,GAAG,IAAI,CAAC,GAAG,CAAC,KAAK,CAAC,CAAC;QACjC,MAAM,GAAG,GAAG,KAAK,CAAC,IAAI,CAAC,EAAE,MAAM,EAAE,QAAQ,EAAE,CAAC,CAAC;QAC7C,IAAI,KAAK,IAAI,CAAC,EAAE;YACd,OAAO,GAAG,CAAC,GAAG,CAAC,CAAC,CAAC,EAAE,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,CAAC;SAC7B;aAAM;YACL,OAAO,GAAG,CAAC,GAAG,CAAC,CAAC,CAAC,EAAE,CAAC,EAAE,EAAE,CAAC,CAAC,GAAG,CAAC,QAAQ,GAAG,CAAC,CAAC,CAAC,CAAC;SAC9C;KACF;IACD,MAAM,GAAG,GAAa,EAAE,CAAC;IACzB,IAAI,IAAI,IAAI,IAAI,EAAE;QAChB,IAAI,GAAG,CAAC,CAAC;KACV;IACD,IAAI,GAAG,IAAI,CAAC,GAAG,CAAC,IAAI,CAAC,CAAC;IACtB,IAAI,KAAK,KAAK,GAAG,EAAE;QACjB,IAAI,KAAK,GAAG,GAAG,EAAE;YACf,KAAK,IAAI,CAAC,GAAG,KAAK,EAAE,CAAC,IAAI,GAAG,EAAE,CAAC,IAAI,IAAI,EAAE;gBACvC,GAAG,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC;aACb;SACF;aAAM;YACL,KAAK,IAAI,CAAC,GAAG,KAAK,EAAE,CAAC,IAAI,GAAG,EAAE,CAAC,IAAI,IAAI,EAA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,CAAC;IAClC,CAAC;;AA3MH,4BA4MC;AAxMiB,aAAI,GAAG,IAAI,QAAQ,EAAE,CAAC;AACtB,YAAG,GAAG,IAAI,QAAQ,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC;AACzB,iBAAQ,GAAG,IAAI,QAAQ,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC;AAyMzC,MAAM,IAAI,GAAG,CAAC,CAAC,GAAG,CAAC,EAAE,CAAC,GAAG,CAAC,EAAE,UAAU,GAAG,KAAK,EAAY,EAAE,CAAC,IAAI,QAAQ,CAAC,CAAC,EAAE,CAAC,EAAE,UAAU,CAAC,CAAC;AAAtF,QAAA,IAAI,QAAkF","sourcesContent":["import { Nullable } from \"./types\";\n\nexport function range(start: number, end: Nullable<number> = null, incr: Nullable<number> = 1): number[] {\n if (end == null) {\n const absStart = Math.abs(start);\n const arr = Array.from({ length: absStart });\n if (start >= 0) {\n return arr.map((x, i) => i);\n } else {\n return arr.map((x, i) => i - (absStart - 1));\n }\n }\n const out: number[] = [];\n if (incr == null) {\n incr = 1;\n }\n incr = Math.abs(incr);\n if (start !== end) {\n if (start < end) {\n for (let i = start; i <= end; i += incr) {\n out.push(i);\n }\n } else {\n for (let i = start; i >= end; i -= incr) {\n out.push(i);\n }\n }\n }\n return out;\n}\n\nexport function gcdof(x: number, y: number): number {\n x = Math.abs(x);\n y = Math.abs(y);\n while (y > 0) {\n const t = y;\n y = x % y;\n x = t;\n }\n return x;\n}\n\nexport class Fraction {\n readonly num: number;\n readonly den: number;\n\n static readonly ZERO = new Fraction();\n static readonly ONE = new Fraction(1, 1);\n static readonly INFINITY = new Fraction(1, 0);\n\n constructor(num = 0, den = 1, factorized = false) {\n if (isNaN(num) || isNaN(den)) {\n throw new Error(`Invalid numerator(${num}) or denminator(${den})`);\n }\n if (factorized) {\n const gcd = gcdof(num, den);\n num /= gcd;\n den /= gcd;\n }\n this.num = num;\n this.den = den;\n }\n\n static parse(val: string, factorized = false): Fraction {\n const parts = val\n .trim()\n .split(\"/\")\n .map((x) => x.trim());\n let num = 1;\n let den = 1;\n if (parts.length == 1) num = parseInt(parts[0]);\n else if (parts.length != 2) {\n throw new Error(\"Invalid fraction string: \" + val);\n } else {\n if (parts[0].length > 0) {\n num = parseInt(parts[0]);\n }\n if (parts[1].length > 0) {\n den = parseInt(parts[1]);\n }\n }\n if (isNaN(num) || isNaN(den)) {\n throw new Error(\"Invalid fraction string: \" + val);\n }\n return new Fraction(num, den, factorized);\n }\n\n get isWhole(): boolean {\n return this.num % this.den == 0;\n }\n\n get isZero(): boolean {\n return this.num == 0;\n }\n\n get isInfinity(): boolean {\n return this.den == 0;\n }\n\n get isOne(): boolean {\n return this.num == this.den;\n }\n\n get ceil(): number {\n if (this.num % this.den == 0) {\n return this.num / this.den;\n } else {\n return 1 + Math.floor(this.num / this.den);\n }\n }\n\n get floor(): number {\n if (this.num % this.den == 0) {\n return this.num / this.den;\n } else {\n return Math.floor(this.num / this.den);\n }\n }\n\n plus(another: Fraction, factorized = false): Fraction {\n return new Fraction(this.num * another.den + this.den * another.num, this.den * another.den, factorized);\n }\n\n plusNum(another: number, factorized = false): Fraction {\n return new Fraction(this.num + this.den * another, this.den, factorized);\n }\n\n minus(another: Fraction, factorized = false): Fraction {\n return new Fraction(this.num * another.den - this.den * another.num, this.den * another.den, factorized);\n }\n\n minusNum(another: number, factorized = false): Fraction {\n return new Fraction(this.num - this.den * another, this.den, factorized);\n }\n\n times(another: Fraction, factorized = false): Fraction {\n return new Fraction(this.num * another.num, this.den * another.den, factorized);\n }\n\n timesNum(another: number, factorized = false): Fraction {\n return new Fraction(this.num * another, this.den, factorized);\n }\n\n divby(another: Fraction, factorized = false): Fraction {\n return new Fraction(this.num * another.den, this.den * another.num, factorized);\n }\n\n divbyNum(another: number, factorized = false): Fraction {\n return new Fraction(this.num, this.den * another, factorized);\n }\n\n /**\n * Returns another / this.\n */\n numDivby(another: number, factorized = false): Fraction {\n return new Fraction(this.den * another, this.num, factorized);\n }\n\n /**\n * Returns this % another\n */\n mod(another: Fraction): Fraction {\n // a (mod b) = a − b ⌊a / b⌋\n const d = this.divby(another);\n const floorOfD = Math.floor(d.num / d.den);\n return this.minus(another.timesNum(floorOfD));\n }\n\n /*\n * Returns this % another\n */\n modNum(another: number): Fraction {\n // a (mod b) = a − b ⌊a / b⌋\n const d = this.divbyNum(another);\n const floorOfD = Math.floor(d.num / d.den);\n return this.minusNum(another * floorOfD);\n }\n\n get inverse(): Fraction {\n return new Fraction(this.den, this.num);\n }\n\n get factorized(): Fraction {\n const gcd = gcdof(this.num, this.den);\n return new Fraction(this.num / gcd, this.den / gcd);\n }\n\n equals(another: Fraction): boolean {\n return this.num * another.den == this.den * another.num;\n }\n\n equalsNum(another: number): boolean {\n return this.num == this.den * another;\n }\n\n cmp(another: Fraction): number {\n return this.num * another.den - this.den * another.num;\n }\n\n cmpNum(another: number): number {\n return this.num - this.den * another;\n }\n\n isLT(another: Fraction): boolean {\n return this.cmp(another) < 0;\n }\n\n isLTE(another: Fraction): boolean {\n return this.cmp(another) <= 0;\n }\n\n isLTNum(another: number): boolean {\n return this.cmpNum(another) < 0;\n }\n\n isLTENum(another: number): boolean {\n return this.cmpNum(another) <= 0;\n }\n\n isGT(another: Fraction): boolean {\n return this.cmp(another) > 0;\n }\n\n isGTE(another: Fraction): boolean {\n return this.cmp(another) >= 0;\n }\n\n isGTNum(another: number): boolean {\n return this.cmpNum(another) > 0;\n }\n\n isGTENum(another: number): boolean {\n return this.cmpNum(another) >= 0;\n }\n\n toString(): string {\n return this.num + \"/\" + this.den;\n }\n\n static max(f1: Fraction, f2: Fraction): Fraction {\n return f1.cmp(f2) > 0 ? f1 : f2;\n }\n\n static min(f1: Fraction, f2: Fraction): Fraction {\n return f1.cmp(f2) < 0 ? f1 : f2;\n }\n}\n\n// Shortcut helper\nexport const Frac = (a = 0, b = 1, factorized = false): Fraction => new Fraction(a, b, factorized);\n"]}
|
|
@@ -35,10 +35,6 @@ export declare class EventEmitter {
|
|
|
35
35
|
}
|
|
36
36
|
export declare class EventHub {
|
|
37
37
|
private _handlers;
|
|
38
|
-
private _muted;
|
|
39
|
-
get isMuted(): boolean;
|
|
40
|
-
mute(): void;
|
|
41
|
-
unmute(): void;
|
|
42
38
|
on(names: Array<string> | string, callback: EventCallback): this;
|
|
43
39
|
removeOn(names: Array<string> | string, callback: EventCallback): this;
|
|
44
40
|
_ensurestrings(names: Array<string> | string): string[];
|
|
@@ -50,6 +46,12 @@ export declare class EventHub {
|
|
|
50
46
|
}, handler: T): this;
|
|
51
47
|
emit(name: string, source: any, payload?: any): boolean;
|
|
52
48
|
dispatchEvent(event: TEvent): boolean;
|
|
49
|
+
static BATCH_EVENTS: string;
|
|
50
|
+
protected _events: TEvent[];
|
|
51
|
+
protected _inBatchMode: boolean;
|
|
52
|
+
startBatchMode(): this;
|
|
53
|
+
cancelBatch(): void;
|
|
54
|
+
commitBatch(): void;
|
|
53
55
|
}
|
|
54
56
|
export declare class StateMachine {
|
|
55
57
|
private _states;
|
package/lib/esm/comms/events.js
CHANGED
|
@@ -65,16 +65,8 @@ export class EventEmitter {
|
|
|
65
65
|
export class EventHub {
|
|
66
66
|
constructor() {
|
|
67
67
|
this._handlers = {};
|
|
68
|
-
this.
|
|
69
|
-
|
|
70
|
-
get isMuted() {
|
|
71
|
-
return this._muted;
|
|
72
|
-
}
|
|
73
|
-
mute() {
|
|
74
|
-
this._muted = true;
|
|
75
|
-
}
|
|
76
|
-
unmute() {
|
|
77
|
-
this._muted = false;
|
|
68
|
+
this._events = [];
|
|
69
|
+
this._inBatchMode = false;
|
|
78
70
|
}
|
|
79
71
|
on(names, callback) {
|
|
80
72
|
return this._addHandler(names, this._handlers, callback);
|
|
@@ -110,7 +102,14 @@ export class EventHub {
|
|
|
110
102
|
return this;
|
|
111
103
|
}
|
|
112
104
|
emit(name, source, payload) {
|
|
113
|
-
|
|
105
|
+
const evt = new TEvent(name, source, payload);
|
|
106
|
+
if (this._inBatchMode) {
|
|
107
|
+
this._events.push(evt);
|
|
108
|
+
return true;
|
|
109
|
+
}
|
|
110
|
+
else {
|
|
111
|
+
return this.dispatchEvent(evt);
|
|
112
|
+
}
|
|
114
113
|
}
|
|
115
114
|
dispatchEvent(event) {
|
|
116
115
|
const evtCallbacks = this._handlers[event.name] || [];
|
|
@@ -121,7 +120,23 @@ export class EventHub {
|
|
|
121
120
|
}
|
|
122
121
|
return true;
|
|
123
122
|
}
|
|
123
|
+
startBatchMode() {
|
|
124
|
+
if (!this._inBatchMode) {
|
|
125
|
+
this._inBatchMode = true;
|
|
126
|
+
}
|
|
127
|
+
return this;
|
|
128
|
+
}
|
|
129
|
+
cancelBatch() {
|
|
130
|
+
this._inBatchMode = false;
|
|
131
|
+
this._events = [];
|
|
132
|
+
}
|
|
133
|
+
commitBatch() {
|
|
134
|
+
this._inBatchMode = false;
|
|
135
|
+
this.emit(EventHub.BATCH_EVENTS, this, this._events);
|
|
136
|
+
this._events = [];
|
|
137
|
+
}
|
|
124
138
|
}
|
|
139
|
+
EventHub.BATCH_EVENTS = "BatchEvents";
|
|
125
140
|
export class StateMachine {
|
|
126
141
|
constructor() {
|
|
127
142
|
this._states = {};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"events.js","sourceRoot":"","sources":["../../../src/comms/events.ts"],"names":[],"mappings":"AAKA,MAAM,OAAO,MAAM;IAiDjB,YAAY,IAAY,EAAE,MAAW,EAAE,OAAa;QA9C3C,SAAI,GAAG,MAAM,CAAC,OAAO,EAAE,CAAC;QAKvB,iBAAY,GAAmB,IAAI,CAAC;QAgB9C,gBAAW,GAAQ,IAAI,CAAC;QAUxB,cAAS,GAAG,KAAK,CAAC;QAKlB,cAAS,GAAc,CAAC,CAAC,CAAC;QAQ1B,aAAQ,GAAa,EAAE,CAAC;QAGtB,IAAI,CAAC,IAAI,GAAG,IAAI,CAAC;QACjB,IAAI,CAAC,MAAM,GAAG,MAAM,CAAC;QACrB,IAAI,CAAC,OAAO,GAAG,OAAO,CAAC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AAI,CAAC,GAAG,KAAK,CAAC;QAC3B,IAAI,MAAM,IAAI,KAAK,EAAE;YACnB,IAAI,CAAC,SAAS,GAAG,KAAK,CAAC,IAAI,CAAC;SAC7B;IACH,CAAC;IASD,MAAM,CAAC,KAAa;QAClB,IAAI,IAAI,CAAC,aAAa,IAAI,IAAI;YAAE,OAAO;QAEvC,MAAM,SAAS,GAAQ,IAAI,CAAC,aAAa,CAAC,MAAM,CAAC,KAAK,CAAC,CAAC;QACxD,IAAI,SAAS,IAAI,IAAI,EAAE;YACrB,IAAI,SAAS,IAAI,EAAE,EAAE;gBACnB,IAAI,IAAI,CAAC,UAAU,IAAI,IAAI,EAAE;oBAC3B,IAAI,CAAC,KAAK,CAAC,IAAI,CAAC,UAAU,CAAC,IAAI,CAAC,CAAC;iBAClC;qBAAM;oBACL,MAAM,IAAI,KAAK,CAAC,6BAA6B,CAAC,CAAC;iBAChD;aACF;iBAAM;gBACL,IAAI,CAAC,KAAK,CAAC,SAAS,CAAC,CAAC;aACvB;SACF;IACH,CAAC;CACF","sourcesContent":["import { Nullable, Timestamp } from \"../types\";\n\n/**\n * Super class of all Events.\n */\nexport class TEvent {\n // Globally unique ID for all events.\n private static counter = 0;\n readonly uuid = TEvent.counter++;\n\n /**\n * The event this event was spawned from (if any).\n */\n protected _spawnedFrom: Nullable<this> = null;\n\n /**\n * Name of the event.\n */\n readonly name: string;\n\n /**\n * Source from which this event is originating.\n */\n readonly source: any;\n\n /**\n * Source state that is set by the source of the event only\n * *it* can use.\n */\n sourceState: any = null;\n\n /**\n * Event specific payload.\n */\n payload: any;\n\n /**\n * Whether the event was cancelled.\n */\n cancelled = false;\n\n /**\n * Timestamp of the event - optional.\n */\n timeStamp: Timestamp = -1;\n\n /**\n * All child events that were spawned from this Event.\n * The parent/spawnedFrom and child event references help us\n * form a call tree/trace of a events as it traverses\n * the system.\n */\n children: TEvent[] = [];\n\n constructor(name: string, source: any, payload?: any) {\n this.name = name;\n this.source = source;\n this.payload = payload;\n }\n\n get spawnedFrom(): Nullable<this> {\n return this._spawnedFrom;\n }\n\n protected setSpawnedFrom(msg: Nullable<this>): void {\n this._spawnedFrom = msg;\n if (msg == null) this._rootEvent = this;\n else this._rootEvent = msg.rootEvent;\n }\n\n spawn(name: string, source: any, payload?: any): TEvent {\n const child = new TEvent(name, source, payload);\n child.setSpawnedFrom(this);\n this.children.push(child);\n return child;\n }\n\n /**\n * The first/root message in the forward chain.\n */\n private _rootEvent: this;\n\n get rootEvent(): this {\n return this._rootEvent as this;\n }\n}\n\nexport class State {\n private static counter = 0;\n stateData: any = null;\n readonly id = State.counter++;\n\n get name(): string {\n return this.constructor.name;\n }\n\n enter(data: any): void {\n this.stateData = data;\n }\n\n handle(event: TEvent): void {\n // todo\n }\n}\n\nexport type EventCallback = ((event: TEvent) => void) | ((event: TEvent) => Promise<void>);\n\nexport class EventEmitter {\n protected _eventHub: EventHub | null;\n constructor() {\n this._eventHub = new EventHub();\n }\n get eventHub(): EventHub | null {\n return this._eventHub;\n }\n set eventHub(hub: EventHub | null) {\n const oldHub = this._eventHub;\n this._eventHub = hub;\n this.eventHubChanged(oldHub);\n }\n protected eventHubChanged(oldHub: EventHub | null): void {\n // Do nothing\n console.log(\"WARNING - EventHub Change Listener not implemented: \", this.constructor.name);\n }\n}\n\nexport class EventHub {\n private _handlers: { [key: string]: Array<EventCallback> } = {};\n private _muted = false;\n\n get isMuted(): boolean {\n return this._muted;\n }\n\n mute(): void {\n this._muted = true;\n }\n\n unmute(): void {\n this._muted = false;\n }\n\n on(names: Array<string> | string, callback: EventCallback): this {\n return this._addHandler(names, this._handlers, callback);\n }\n\n removeOn(names: Array<string> | string, callback: EventCallback): this {\n return this._removeHandler(names, this._handlers, callback);\n }\n\n _ensurestrings(names: Array<string> | string): string[] {\n if (typeof names === \"string\") {\n names = (names as string).split(\",\");\n }\n return names.map(function (v) {\n return v.trim();\n });\n }\n\n _addHandler<T>(names: Array<string> | string, handlerlist: { [key: string]: Array<T> }, handler: T): this {\n this._ensurestrings(names).forEach(function (name) {\n handlerlist[name] = handlerlist[name] || [];\n handlerlist[name].push(handler);\n });\n return this;\n }\n\n _removeHandler<T>(names: Array<string> | string, handlerlist: { [key: string]: Array<T> }, handler: T): this {\n this._ensurestrings(names).forEach(function (name) {\n const evHandlers = handlerlist[name] || [];\n for (let i = 0; i < evHandlers.length; i++) {\n if (evHandlers[i] == handler) {\n evHandlers.splice(i, 1);\n break;\n }\n }\n });\n return this;\n }\n\n emit(name: string, source: any, payload?: any): boolean {\n return this.dispatchEvent(new TEvent(name, source, payload));\n }\n\n dispatchEvent(event: TEvent): boolean {\n const evtCallbacks = this._handlers[event.name] || [];\n for (const callback of evtCallbacks) {\n callback(event);\n if (event.cancelled) return false;\n }\n return true;\n }\n}\n\n/**\n * StateMachines allow declarative and stateful chaining of events.\n */\nexport class StateMachine {\n private _states: { [key: string]: State } = {};\n private _rootState: Nullable<State> = null;\n private _currentState: Nullable<State> = null;\n constructor() {\n this._states = {};\n this._rootState = null;\n this._currentState = null;\n }\n\n /**\n * The starting/root state of the machine.\n *\n * @param {String} name Name of the default/root state.\n */\n set rootState(name: string) {\n this._rootState = this.getState(name);\n if (this._currentState == null) {\n this._currentState = this._rootState;\n }\n }\n\n /**\n * Exits the current state (if any) and enters a new state.\n *\n * @param {String} state Name of the new state to enter.\n * @param {Object} data State specific data for the state handler to use for the new state.\n */\n enter(state: string, data: any = null): void {\n if (state == \"\") {\n this._currentState = this._rootState;\n } else {\n this._currentState = this.getState(state);\n }\n if (this._currentState != null) {\n this._currentState.enter(data);\n }\n }\n\n /**\n * Get the state by name.\n *\n * @param {String} name Name of the state being queried.\n * @returns {State} State object associated with the name.\n */\n getState(name: string): State {\n if (!(name in this._states)) {\n throw Error(\"State '\" + name + \"' not yet registered.\");\n }\n return this._states[name];\n }\n\n /**\n * Register a new state in the state machine.\n *\n * @param {State} state State being registered. If another State with\n * the same name exists, then a {DuplicateError} is thrown.\n * @param {Bool} isRoot Whether the new state is a root state.\n */\n registerState(state: State, isRoot = false): void {\n const name = state.name;\n if (name in this._states) {\n throw Error(\"State '\" + name + \"' already registered.\");\n }\n this._states[name] = state;\n if (isRoot || false) {\n this.rootState = state.name;\n }\n }\n\n /**\n * Handles an event from the current state in the state machine possibly resulting in a state transition.\n *\n * @param {Object} name Type of event being sent.\n * @param {EventSource} source The source generating the event.\n * @param {Object} data The event specific data.\n */\n handle(event: TEvent): void {\n if (this._currentState == null) return;\n\n const nextState: any = this._currentState.handle(event);\n if (nextState != null) {\n if (nextState == \"\") {\n if (this._rootState != null) {\n this.enter(this._rootState.name);\n } else {\n throw new Error(\"Root state has not been set\");\n }\n } else {\n this.enter(nextState);\n }\n }\n }\n}\n"]}
|
|
1
|
+
{"version":3,"file":"events.js","sourceRoot":"","sources":["../../../src/comms/events.ts"],"names":[],"mappings":"AAKA,MAAM,OAAO,MAAM;IAiDjB,YAAY,IAAY,EAAE,MAAW,EAAE,OAAa;QA9C3C,SAAI,GAAG,MAAM,CAAC,OAAO,EAAE,CAAC;QAKvB,iBAAY,GAAmB,IAAI,CAAC;QAgB9C,gBAAW,GAAQ,IAAI,CAAC;QAUxB,cAAS,GAAG,KAAK,CAAC;QAKlB,cAAS,GAAc,CAAC,CAAC,CAAC;QAQ1B,aAAQ,GAAa,EAAE,CAAC;QAGtB,IAAI,CAAC,IAAI,GAAG,IAAI,CAAC;QACjB,IAAI,CAAC,MAAM,GAAG,MAAM,CAAC;QACrB,IAAI,CAAC,OAAO,GAAG,OAAO,CAAC;IACzB,CAAC;IAED,IAAI,WAAW;QACb,OAAO,IAAI,CAAC,YAAY,CAAC;IAC3B,CAAC;IAES,cAAc,CAAC,GAAmB;QAC1C,IAAI,CAAC,YAAY,GAAG,GAAG,CAAC;QACxB,IAAI,GAAG,IAAI,IAAI;YAAE,IAAI,CAAC,UAAU,GAAG,IAAI,CAAC;;YACnC,IAAI,CAAC,UAAU,GAAG,GAAG,CAAC,SAAS,CAAC;IACvC,CAAC;IAED,KAAK,CAAC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M,IAAI,GAAG,KAAK,CAAC,IAAI,CAAC;QACxB,IAAI,IAAI,IAAI,IAAI,CAAC,OAAO,EAAE;YACxB,MAAM,KAAK,CAAC,SAAS,GAAG,IAAI,GAAG,uBAAuB,CAAC,CAAC;SACzD;QACD,IAAI,CAAC,OAAO,CAAC,IAAI,CAAC,GAAG,KAAK,CAAC;QAC3B,IAAI,MAAM,IAAI,KAAK,EAAE;YACnB,IAAI,CAAC,SAAS,GAAG,KAAK,CAAC,IAAI,CAAC;SAC7B;IACH,CAAC;IASD,MAAM,CAAC,KAAa;QAClB,IAAI,IAAI,CAAC,aAAa,IAAI,IAAI;YAAE,OAAO;QAEvC,MAAM,SAAS,GAAQ,IAAI,CAAC,aAAa,CAAC,MAAM,CAAC,KAAK,CAAC,CAAC;QACxD,IAAI,SAAS,IAAI,IAAI,EAAE;YACrB,IAAI,SAAS,IAAI,EAAE,EAAE;gBACnB,IAAI,IAAI,CAAC,UAAU,IAAI,IAAI,EAAE;oBAC3B,IAAI,CAAC,KAAK,CAAC,IAAI,CAAC,UAAU,CAAC,IAAI,CAAC,CAAC;iBAClC;qBAAM;oBACL,MAAM,IAAI,KAAK,CAAC,6BAA6B,CAAC,CAAC;iBAChD;aACF;iBAAM;gBACL,IAAI,CAAC,KAAK,CAAC,SAAS,CAAC,CAAC;aACvB;SACF;IACH,CAAC;CACF","sourcesContent":["import { Nullable, Timestamp } from \"../types\";\n\n/**\n * Super class of all Events.\n */\nexport class TEvent {\n // Globally unique ID for all events.\n private static counter = 0;\n readonly uuid = TEvent.counter++;\n\n /**\n * The event this event was spawned from (if any).\n */\n protected _spawnedFrom: Nullable<this> = null;\n\n /**\n * Name of the event.\n */\n readonly name: string;\n\n /**\n * Source from which this event is originating.\n */\n readonly source: any;\n\n /**\n * Source state that is set by the source of the event only\n * *it* can use.\n */\n sourceState: any = null;\n\n /**\n * Event specific payload.\n */\n payload: any;\n\n /**\n * Whether the event was cancelled.\n */\n cancelled = false;\n\n /**\n * Timestamp of the event - optional.\n */\n timeStamp: Timestamp = -1;\n\n /**\n * All child events that were spawned from this Event.\n * The parent/spawnedFrom and child event references help us\n * form a call tree/trace of a events as it traverses\n * the system.\n */\n children: TEvent[] = [];\n\n constructor(name: string, source: any, payload?: any) {\n this.name = name;\n this.source = source;\n this.payload = payload;\n }\n\n get spawnedFrom(): Nullable<this> {\n return this._spawnedFrom;\n }\n\n protected setSpawnedFrom(msg: Nullable<this>): void {\n this._spawnedFrom = msg;\n if (msg == null) this._rootEvent = this;\n else this._rootEvent = msg.rootEvent;\n }\n\n spawn(name: string, source: any, payload?: any): TEvent {\n const child = new TEvent(name, source, payload);\n child.setSpawnedFrom(this);\n this.children.push(child);\n return child;\n }\n\n /**\n * The first/root message in the forward chain.\n */\n private _rootEvent: this;\n\n get rootEvent(): this {\n return this._rootEvent as this;\n }\n}\n\nexport class State {\n private static counter = 0;\n stateData: any = null;\n readonly id = State.counter++;\n\n get name(): string {\n return this.constructor.name;\n }\n\n enter(data: any): void {\n this.stateData = data;\n }\n\n handle(event: TEvent): void {\n // todo\n }\n}\n\nexport type EventCallback = ((event: TEvent) => void) | ((event: TEvent) => Promise<void>);\n\nexport class EventEmitter {\n protected _eventHub: EventHub | null;\n constructor() {\n this._eventHub = new EventHub();\n }\n get eventHub(): EventHub | null {\n return this._eventHub;\n }\n set eventHub(hub: EventHub | null) {\n const oldHub = this._eventHub;\n this._eventHub = hub;\n this.eventHubChanged(oldHub);\n }\n protected eventHubChanged(oldHub: EventHub | null): void {\n // Do nothing\n console.log(\"WARNING - EventHub Change Listener not implemented: \", this.constructor.name);\n }\n}\n\nexport class EventHub {\n private _handlers: { [key: string]: Array<EventCallback> } = {};\n\n on(names: Array<string> | string, callback: EventCallback): this {\n return this._addHandler(names, this._handlers, callback);\n }\n\n removeOn(names: Array<string> | string, callback: EventCallback): this {\n return this._removeHandler(names, this._handlers, callback);\n }\n\n _ensurestrings(names: Array<string> | string): string[] {\n if (typeof names === \"string\") {\n names = (names as string).split(\",\");\n }\n return names.map(function (v) {\n return v.trim();\n });\n }\n\n _addHandler<T>(names: Array<string> | string, handlerlist: { [key: string]: Array<T> }, handler: T): this {\n this._ensurestrings(names).forEach(function (name) {\n handlerlist[name] = handlerlist[name] || [];\n handlerlist[name].push(handler);\n });\n return this;\n }\n\n _removeHandler<T>(names: Array<string> | string, handlerlist: { [key: string]: Array<T> }, handler: T): this {\n this._ensurestrings(names).forEach(function (name) {\n const evHandlers = handlerlist[name] || [];\n for (let i = 0; i < evHandlers.length; i++) {\n if (evHandlers[i] == handler) {\n evHandlers.splice(i, 1);\n break;\n }\n }\n });\n return this;\n }\n\n emit(name: string, source: any, payload?: any): boolean {\n const evt = new TEvent(name, source, payload);\n if (this._inBatchMode) {\n this._events.push(evt);\n return true;\n } else {\n return this.dispatchEvent(evt);\n }\n }\n\n dispatchEvent(event: TEvent): boolean {\n const evtCallbacks = this._handlers[event.name] || [];\n for (const callback of evtCallbacks) {\n callback(event);\n if (event.cancelled) return false;\n }\n return true;\n }\n\n // Support for transactional/batch event handling, where\n // the user can allow a bunch of events to first collect\n // before triggering a batch dispatch\n public static BATCH_EVENTS = \"BatchEvents\";\n protected _events: TEvent[] = [];\n protected _inBatchMode = false;\n startBatchMode(): this {\n if (!this._inBatchMode) {\n this._inBatchMode = true;\n }\n return this;\n }\n\n cancelBatch(): void {\n this._inBatchMode = false;\n this._events = [];\n }\n\n commitBatch(): void {\n this._inBatchMode = false;\n this.emit(EventHub.BATCH_EVENTS, this, this._events);\n this._events = [];\n }\n}\n\n/**\n * StateMachines allow declarative and stateful chaining of events.\n */\nexport class StateMachine {\n private _states: { [key: string]: State } = {};\n private _rootState: Nullable<State> = null;\n private _currentState: Nullable<State> = null;\n constructor() {\n this._states = {};\n this._rootState = null;\n this._currentState = null;\n }\n\n /**\n * The starting/root state of the machine.\n *\n * @param {String} name Name of the default/root state.\n */\n set rootState(name: string) {\n this._rootState = this.getState(name);\n if (this._currentState == null) {\n this._currentState = this._rootState;\n }\n }\n\n /**\n * Exits the current state (if any) and enters a new state.\n *\n * @param {String} state Name of the new state to enter.\n * @param {Object} data State specific data for the state handler to use for the new state.\n */\n enter(state: string, data: any = null): void {\n if (state == \"\") {\n this._currentState = this._rootState;\n } else {\n this._currentState = this.getState(state);\n }\n if (this._currentState != null) {\n this._currentState.enter(data);\n }\n }\n\n /**\n * Get the state by name.\n *\n * @param {String} name Name of the state being queried.\n * @returns {State} State object associated with the name.\n */\n getState(name: string): State {\n if (!(name in this._states)) {\n throw Error(\"State '\" + name + \"' not yet registered.\");\n }\n return this._states[name];\n }\n\n /**\n * Register a new state in the state machine.\n *\n * @param {State} state State being registered. If another State with\n * the same name exists, then a {DuplicateError} is thrown.\n * @param {Bool} isRoot Whether the new state is a root state.\n */\n registerState(state: State, isRoot = false): void {\n const name = state.name;\n if (name in this._states) {\n throw Error(\"State '\" + name + \"' already registered.\");\n }\n this._states[name] = state;\n if (isRoot || false) {\n this.rootState = state.name;\n }\n }\n\n /**\n * Handles an event from the current state in the state machine possibly resulting in a state transition.\n *\n * @param {Object} name Type of event being sent.\n * @param {EventSource} source The source generating the event.\n * @param {Object} data The event specific data.\n */\n handle(event: TEvent): void {\n if (this._currentState == null) return;\n\n const nextState: any = this._currentState.handle(event);\n if (nextState != null) {\n if (nextState == \"\") {\n if (this._rootState != null) {\n this.enter(this._rootState.name);\n } else {\n throw new Error(\"Root state has not been set\");\n }\n } else {\n this.enter(nextState);\n }\n }\n }\n}\n"]}
|
package/lib/esm/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,SAAS,CAAC;uBACH,cAAc;kBAAvB,GAAG;6BACY,aAAa;wBAA5B,SAAS;0BACG,gBAAgB;qBAA5B,MAAM;yBACK,QAAQ;oBAAnB,KAAK;wBACK,QAAQ;mBAAlB,IAAI;2BACS,WAAW;sBAAxB,OAAO;uBACE,OAAO;kBAAhB,GAAG;wBACO,QAAQ;mBAAlB,IAAI;uBACK,eAAe;kBAAxB,GAAG;wBACO,aAAa;mBAAvB,IAAI;
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,SAAS,CAAC;uBACH,cAAc;kBAAvB,GAAG;6BACY,aAAa;wBAA5B,SAAS;0BACG,gBAAgB;qBAA5B,MAAM;yBACK,QAAQ;oBAAnB,KAAK;wBACK,QAAQ;mBAAlB,IAAI;2BACS,WAAW;sBAAxB,OAAO;uBACE,OAAO;kBAAhB,GAAG;wBACO,QAAQ;mBAAlB,IAAI;uBACK,eAAe;kBAAxB,GAAG;wBACO,aAAa;mBAAvB,IAAI;uBACK,OAAO;kBAAhB,GAAG;AACf,OAAO,EAAE,OAAO,EAAE,MAAM,WAAW,CAAC","sourcesContent":["export * from \"./types\";\nexport * as Api from \"./apis/index\";\nexport * as Constants from \"./constants\";\nexport * as Events from \"./comms/events\";\nexport * as Lists from \"./list\";\nexport * as Misc from \"./misc\";\nexport * as Streams from \"./streams\";\nexport * as DOM from \"./dom\";\nexport * as Geom from \"./geom\";\nexport * as Num from \"./numberutils\";\nexport * as Time from \"./timeutils\";\nexport * as DAL from \"./dal\";\nexport { Browser } from \"./browser\";\n"]}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"numberutils.js","sourceRoot":"","sources":["../../src/numberutils.ts"],"names":[],"mappings":"AAEA,MAAM,UAAU,KAAK,CAAC,KAAa,EAAE,MAAwB,IAAI,EAAE,OAAyB,CAAC;IAC3F,IAAI,GAAG,IAAI,IAAI,EAAE;QACf,MAAM,QAAQ,GAAG,IAAI,CAAC,GAAG,CAAC,KAAK,CAAC,CAAC;QACjC,MAAM,GAAG,GAAG,KAAK,CAAC,IAAI,CAAC,EAAE,MAAM,EAAE,QAAQ,EAAE,CAAC,CAAC;QAC7C,IAAI,KAAK,IAAI,CAAC,EAAE;YACd,OAAO,GAAG,CAAC,GAA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AI,CAAC,GAAG,CAAC,OAAO,CAAC,IAAI,CAAC,CAAC;IAChC,CAAC;IAED,OAAO,CAAC,OAAe;QACrB,OAAO,IAAI,CAAC,MAAM,CAAC,OAAO,CAAC,GAAG,CAAC,CAAC;IAClC,CAAC;IAED,QAAQ,CAAC,OAAe;QACtB,OAAO,IAAI,CAAC,MAAM,CAAC,OAAO,CAAC,IAAI,CAAC,CAAC;IACnC,CAAC;IAED,QAAQ;QACN,OAAO,IAAI,CAAC,GAAG,GAAG,GAAG,GAAG,IAAI,CAAC,GAAG,CAAC;IACnC,CAAC;IAED,MAAM,CAAC,GAAG,CAAC,EAAY,EAAE,EAAY;QACnC,OAAO,EAAE,CAAC,GAAG,CAAC,EAAE,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,EAAE,CAAC;IAClC,CAAC;IAED,MAAM,CAAC,GAAG,CAAC,EAAY,EAAE,EAAY;QACnC,OAAO,EAAE,CAAC,GAAG,CAAC,EAAE,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,EAAE,CAAC;IAClC,CAAC;;AAvMe,aAAI,GAAG,IAAI,QAAQ,EAAE,CAAC;AACtB,YAAG,GAAG,IAAI,QAAQ,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC;AACzB,iBAAQ,GAAG,IAAI,QAAQ,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC;AAyMhD,MAAM,CAAC,MAAM,IAAI,GAAG,CAAC,CAAC,GAAG,CAAC,EAAE,CAAC,GAAG,CAAC,EAAE,UAAU,GAAG,KAAK,EAAY,EAAE,CAAC,IAAI,QAAQ,CAAC,CAAC,EAAE,CAAC,EAAE,UAAU,CAAC,CAAC","sourcesContent":["import { Nullable } from \"./types\";\n\nexport function range(start: number, end: Nullable<number> = null, incr: Nullable<number> = 1): number[] {\n if (end == null) {\n const absStart = Math.abs(start);\n const arr = Array.from({ length: absStart });\n if (start >= 0) {\n return arr.map((x, i) => i);\n } else {\n return arr.map((x, i) => i - (absStart - 1));\n }\n }\n const out: number[] = [];\n if (incr == null) {\n incr = 1;\n }\n incr = Math.abs(incr);\n if (start !== end) {\n if (start < end) {\n for (let i = start; i <= end; i += incr) {\n out.push(i);\n }\n } else {\n for (let i = start; i >= end; i -= incr) {\n out.push(i);\n }\n }\n }\n return out;\n}\n\n/*\nexport function applyMixins(derivedCtor: any, baseCtors: any[]) {\n baseCtors.forEach(baseCtor => {\n Object.getOwnPropertyNames(baseCtor.prototype).forEach(name => {\n Object.defineProperty(derivedCtor.prototype, name,\n Object.getOwnPropertyDescriptor(baseCtor.prototype, name));\n });\n });\n}\n*/\n\nexport function gcdof(x: number, y: number): number {\n x = Math.abs(x);\n y = Math.abs(y);\n while (y > 0) {\n const t = y;\n y = x % y;\n x = t;\n }\n return x;\n}\n\nexport class Fraction {\n readonly num: number;\n readonly den: number;\n\n static readonly ZERO = new Fraction();\n static readonly ONE = new Fraction(1, 1);\n static readonly INFINITY = new Fraction(1, 0);\n\n constructor(num = 0, den = 1, factorized = false) {\n if (isNaN(num) || isNaN(den)) {\n throw new Error(`Invalid numerator(${num}) or denminator(${den})`);\n }\n if (factorized) {\n const gcd = gcdof(num, den);\n num /= gcd;\n den /= gcd;\n }\n this.num = num;\n this.den = den;\n }\n\n static parse(val: string, factorized = false): Fraction {\n const parts = val\n .trim()\n .split(\"/\")\n .map((x) => x.trim());\n let num = 1;\n let den = 1;\n if (parts.length == 1) num = parseInt(parts[0]);\n else if (parts.length != 2) {\n throw new Error(\"Invalid fraction string: \" + val);\n } else {\n if (parts[0].length > 0) {\n num = parseInt(parts[0]);\n }\n if (parts[1].length > 0) {\n den = parseInt(parts[1]);\n }\n }\n if (isNaN(num) || isNaN(den)) {\n throw new Error(\"Invalid fraction string: \" + val);\n }\n return new Fraction(num, den, factorized);\n }\n\n get isWhole(): boolean {\n return this.num % this.den == 0;\n }\n\n get isZero(): boolean {\n return this.num == 0;\n }\n\n get isInfinity(): boolean {\n return this.den == 0;\n }\n\n get isOne(): boolean {\n return this.num == this.den;\n }\n\n get ceil(): number {\n if (this.num % this.den == 0) {\n return this.num / this.den;\n } else {\n return 1 + Math.floor(this.num / this.den);\n }\n }\n\n get floor(): number {\n if (this.num % this.den == 0) {\n return this.num / this.den;\n } else {\n return Math.floor(this.num / this.den);\n }\n }\n\n plus(another: Fraction, factorized = false): Fraction {\n return new Fraction(this.num * another.den + this.den * another.num, this.den * another.den, factorized);\n }\n\n plusNum(another: number, factorized = false): Fraction {\n return new Fraction(this.num + this.den * another, this.den, factorized);\n }\n\n minus(another: Fraction, factorized = false): Fraction {\n return new Fraction(this.num * another.den - this.den * another.num, this.den * another.den, factorized);\n }\n\n minusNum(another: number, factorized = false): Fraction {\n return new Fraction(this.num - this.den * another, this.den, factorized);\n }\n\n times(another: Fraction, factorized = false): Fraction {\n return new Fraction(this.num * another.num, this.den * another.den, factorized);\n }\n\n timesNum(another: number, factorized = false): Fraction {\n return new Fraction(this.num * another, this.den, factorized);\n }\n\n divby(another: Fraction, factorized = false): Fraction {\n return new Fraction(this.num * another.den, this.den * another.num, factorized);\n }\n\n divbyNum(another: number, factorized = false): Fraction {\n return new Fraction(this.num, this.den * another, factorized);\n }\n\n /**\n * Returns another / this.\n */\n numDivby(another: number, factorized = false): Fraction {\n return new Fraction(this.den * another, this.num, factorized);\n }\n\n /**\n * Returns this % another\n */\n mod(another: Fraction): Fraction {\n // a (mod b) = a − b ⌊a / b⌋\n const d = this.divby(another);\n const floorOfD = Math.floor(d.num / d.den);\n return this.minus(another.timesNum(floorOfD));\n }\n\n /*\n * Returns this % another\n */\n modNum(another: number): Fraction {\n // a (mod b) = a − b ⌊a / b⌋\n const d = this.divbyNum(another);\n const floorOfD = Math.floor(d.num / d.den);\n return this.minusNum(another * floorOfD);\n }\n\n get inverse(): Fraction {\n return new Fraction(this.den, this.num);\n }\n\n get factorized(): Fraction {\n const gcd = gcdof(this.num, this.den);\n return new Fraction(this.num / gcd, this.den / gcd);\n }\n\n equals(another: Fraction): boolean {\n return this.num * another.den == this.den * another.num;\n }\n\n equalsNum(another: number): boolean {\n return this.num == this.den * another;\n }\n\n cmp(another: Fraction): number {\n return this.num * another.den - this.den * another.num;\n }\n\n cmpNum(another: number): number {\n return this.num - this.den * another;\n }\n\n isLT(another: Fraction): boolean {\n return this.cmp(another) < 0;\n }\n\n isLTE(another: Fraction): boolean {\n return this.cmp(another) <= 0;\n }\n\n isLTNum(another: number): boolean {\n return this.cmpNum(another) < 0;\n }\n\n isLTENum(another: number): boolean {\n return this.cmpNum(another) <= 0;\n }\n\n isGT(another: Fraction): boolean {\n return this.cmp(another) > 0;\n }\n\n isGTE(another: Fraction): boolean {\n return this.cmp(another) >= 0;\n }\n\n isGTNum(another: number): boolean {\n return this.cmpNum(another) > 0;\n }\n\n isGTENum(another: number): boolean {\n return this.cmpNum(another) >= 0;\n }\n\n toString(): string {\n return this.num + \"/\" + this.den;\n }\n\n static max(f1: Fraction, f2: Fraction): Fraction {\n return f1.cmp(f2) > 0 ? f1 : f2;\n }\n\n static min(f1: Fraction, f2: Fraction): Fraction {\n return f1.cmp(f2) < 0 ? f1 : f2;\n }\n}\n\n// Shortcut helper\nexport const Frac = (a = 0, b = 1, factorized = false): Fraction => new Fraction(a, b, factorized);\n"]}
|
|
1
|
+
{"version":3,"file":"numberutils.js","sourceRoot":"","sources":["../../src/numberutils.ts"],"names":[],"mappings":"AAEA,MAAM,UAAU,KAAK,CAAC,KAAa,EAAE,MAAwB,IAAI,EAAE,OAAyB,CAAC;IAC3F,IAAI,GAAG,IAAI,IAAI,EAAE;QACf,MAAM,QAAQ,GAAG,IAAI,CAAC,GAAG,CAAC,KAAK,CAAC,CAAC;QACjC,MAAM,GAAG,GAAG,KAAK,CAAC,IAAI,CAAC,EAAE,MAAM,EAAE,QAAQ,EAAE,CAAC,CAAC;QAC7C,IAAI,KAAK,IAAI,CAAC,EAAE;YACd,OAAO,GAAG,CAAC,GAAG,CAAC,CAAC,CAAC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,OAAO,CAAC,IAAI,CAAC,CAAC;IAChC,CAAC;IAED,OAAO,CAAC,OAAe;QACrB,OAAO,IAAI,CAAC,MAAM,CAAC,OAAO,CAAC,GAAG,CAAC,CAAC;IAClC,CAAC;IAED,QAAQ,CAAC,OAAe;QACtB,OAAO,IAAI,CAAC,MAAM,CAAC,OAAO,CAAC,IAAI,CAAC,CAAC;IACnC,CAAC;IAED,QAAQ;QACN,OAAO,IAAI,CAAC,GAAG,GAAG,GAAG,GAAG,IAAI,CAAC,GAAG,CAAC;IACnC,CAAC;IAED,MAAM,CAAC,GAAG,CAAC,EAAY,EAAE,EAAY;QACnC,OAAO,EAAE,CAAC,GAAG,CAAC,EAAE,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,EAAE,CAAC;IAClC,CAAC;IAED,MAAM,CAAC,GAAG,CAAC,EAAY,EAAE,EAAY;QACnC,OAAO,EAAE,CAAC,GAAG,CAAC,EAAE,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,EAAE,CAAC;IAClC,CAAC;;AAvMe,aAAI,GAAG,IAAI,QAAQ,EAAE,CAAC;AACtB,YAAG,GAAG,IAAI,QAAQ,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC;AACzB,iBAAQ,GAAG,IAAI,QAAQ,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC;AAyMhD,MAAM,CAAC,MAAM,IAAI,GAAG,CAAC,CAAC,GAAG,CAAC,EAAE,CAAC,GAAG,CAAC,EAAE,UAAU,GAAG,KAAK,EAAY,EAAE,CAAC,IAAI,QAAQ,CAAC,CAAC,EAAE,CAAC,EAAE,UAAU,CAAC,CAAC","sourcesContent":["import { Nullable } from \"./types\";\n\nexport function range(start: number, end: Nullable<number> = null, incr: Nullable<number> = 1): number[] {\n if (end == null) {\n const absStart = Math.abs(start);\n const arr = Array.from({ length: absStart });\n if (start >= 0) {\n return arr.map((x, i) => i);\n } else {\n return arr.map((x, i) => i - (absStart - 1));\n }\n }\n const out: number[] = [];\n if (incr == null) {\n incr = 1;\n }\n incr = Math.abs(incr);\n if (start !== end) {\n if (start < end) {\n for (let i = start; i <= end; i += incr) {\n out.push(i);\n }\n } else {\n for (let i = start; i >= end; i -= incr) {\n out.push(i);\n }\n }\n }\n return out;\n}\n\nexport function gcdof(x: number, y: number): number {\n x = Math.abs(x);\n y = Math.abs(y);\n while (y > 0) {\n const t = y;\n y = x % y;\n x = t;\n }\n return x;\n}\n\nexport class Fraction {\n readonly num: number;\n readonly den: number;\n\n static readonly ZERO = new Fraction();\n static readonly ONE = new Fraction(1, 1);\n static readonly INFINITY = new Fraction(1, 0);\n\n constructor(num = 0, den = 1, factorized = false) {\n if (isNaN(num) || isNaN(den)) {\n throw new Error(`Invalid numerator(${num}) or denminator(${den})`);\n }\n if (factorized) {\n const gcd = gcdof(num, den);\n num /= gcd;\n den /= gcd;\n }\n this.num = num;\n this.den = den;\n }\n\n static parse(val: string, factorized = false): Fraction {\n const parts = val\n .trim()\n .split(\"/\")\n .map((x) => x.trim());\n let num = 1;\n let den = 1;\n if (parts.length == 1) num = parseInt(parts[0]);\n else if (parts.length != 2) {\n throw new Error(\"Invalid fraction string: \" + val);\n } else {\n if (parts[0].length > 0) {\n num = parseInt(parts[0]);\n }\n if (parts[1].length > 0) {\n den = parseInt(parts[1]);\n }\n }\n if (isNaN(num) || isNaN(den)) {\n throw new Error(\"Invalid fraction string: \" + val);\n }\n return new Fraction(num, den, factorized);\n }\n\n get isWhole(): boolean {\n return this.num % this.den == 0;\n }\n\n get isZero(): boolean {\n return this.num == 0;\n }\n\n get isInfinity(): boolean {\n return this.den == 0;\n }\n\n get isOne(): boolean {\n return this.num == this.den;\n }\n\n get ceil(): number {\n if (this.num % this.den == 0) {\n return this.num / this.den;\n } else {\n return 1 + Math.floor(this.num / this.den);\n }\n }\n\n get floor(): number {\n if (this.num % this.den == 0) {\n return this.num / this.den;\n } else {\n return Math.floor(this.num / this.den);\n }\n }\n\n plus(another: Fraction, factorized = false): Fraction {\n return new Fraction(this.num * another.den + this.den * another.num, this.den * another.den, factorized);\n }\n\n plusNum(another: number, factorized = false): Fraction {\n return new Fraction(this.num + this.den * another, this.den, factorized);\n }\n\n minus(another: Fraction, factorized = false): Fraction {\n return new Fraction(this.num * another.den - this.den * another.num, this.den * another.den, factorized);\n }\n\n minusNum(another: number, factorized = false): Fraction {\n return new Fraction(this.num - this.den * another, this.den, factorized);\n }\n\n times(another: Fraction, factorized = false): Fraction {\n return new Fraction(this.num * another.num, this.den * another.den, factorized);\n }\n\n timesNum(another: number, factorized = false): Fraction {\n return new Fraction(this.num * another, this.den, factorized);\n }\n\n divby(another: Fraction, factorized = false): Fraction {\n return new Fraction(this.num * another.den, this.den * another.num, factorized);\n }\n\n divbyNum(another: number, factorized = false): Fraction {\n return new Fraction(this.num, this.den * another, factorized);\n }\n\n /**\n * Returns another / this.\n */\n numDivby(another: number, factorized = false): Fraction {\n return new Fraction(this.den * another, this.num, factorized);\n }\n\n /**\n * Returns this % another\n */\n mod(another: Fraction): Fraction {\n // a (mod b) = a − b ⌊a / b⌋\n const d = this.divby(another);\n const floorOfD = Math.floor(d.num / d.den);\n return this.minus(another.timesNum(floorOfD));\n }\n\n /*\n * Returns this % another\n */\n modNum(another: number): Fraction {\n // a (mod b) = a − b ⌊a / b⌋\n const d = this.divbyNum(another);\n const floorOfD = Math.floor(d.num / d.den);\n return this.minusNum(another * floorOfD);\n }\n\n get inverse(): Fraction {\n return new Fraction(this.den, this.num);\n }\n\n get factorized(): Fraction {\n const gcd = gcdof(this.num, this.den);\n return new Fraction(this.num / gcd, this.den / gcd);\n }\n\n equals(another: Fraction): boolean {\n return this.num * another.den == this.den * another.num;\n }\n\n equalsNum(another: number): boolean {\n return this.num == this.den * another;\n }\n\n cmp(another: Fraction): number {\n return this.num * another.den - this.den * another.num;\n }\n\n cmpNum(another: number): number {\n return this.num - this.den * another;\n }\n\n isLT(another: Fraction): boolean {\n return this.cmp(another) < 0;\n }\n\n isLTE(another: Fraction): boolean {\n return this.cmp(another) <= 0;\n }\n\n isLTNum(another: number): boolean {\n return this.cmpNum(another) < 0;\n }\n\n isLTENum(another: number): boolean {\n return this.cmpNum(another) <= 0;\n }\n\n isGT(another: Fraction): boolean {\n return this.cmp(another) > 0;\n }\n\n isGTE(another: Fraction): boolean {\n return this.cmp(another) >= 0;\n }\n\n isGTNum(another: number): boolean {\n return this.cmpNum(another) > 0;\n }\n\n isGTENum(another: number): boolean {\n return this.cmpNum(another) >= 0;\n }\n\n toString(): string {\n return this.num + \"/\" + this.den;\n }\n\n static max(f1: Fraction, f2: Fraction): Fraction {\n return f1.cmp(f2) > 0 ? f1 : f2;\n }\n\n static min(f1: Fraction, f2: Fraction): Fraction {\n return f1.cmp(f2) < 0 ? f1 : f2;\n }\n}\n\n// Shortcut helper\nexport const Frac = (a = 0, b = 1, factorized = false): Fraction => new Fraction(a, b, factorized);\n"]}
|
package/package.json
CHANGED
package/lib/cjs/properties.d.ts
DELETED
|
@@ -1,54 +0,0 @@
|
|
|
1
|
-
import { Nullable } from "./types";
|
|
2
|
-
export declare class PropertySchema {
|
|
3
|
-
name: string;
|
|
4
|
-
units: string;
|
|
5
|
-
defaultValue: any;
|
|
6
|
-
minValue: Nullable<number>;
|
|
7
|
-
maxValue: Nullable<number>;
|
|
8
|
-
beforeSetterName: Nullable<string>;
|
|
9
|
-
constructor(name: string, config: any);
|
|
10
|
-
validate(newValue: number): boolean;
|
|
11
|
-
}
|
|
12
|
-
export declare class Property {
|
|
13
|
-
readonly schema: PropertySchema;
|
|
14
|
-
currentValue: any;
|
|
15
|
-
beforeSetterFunc: any;
|
|
16
|
-
constructor(schema: PropertySchema);
|
|
17
|
-
clone(): Property;
|
|
18
|
-
get value(): any;
|
|
19
|
-
setValue(instance: any, value: any): boolean;
|
|
20
|
-
}
|
|
21
|
-
export declare class PropertyStore {
|
|
22
|
-
readonly __properties__: {
|
|
23
|
-
[key: string]: Property;
|
|
24
|
-
};
|
|
25
|
-
private eventBus;
|
|
26
|
-
getPropertyNames(): string[];
|
|
27
|
-
getProperty(name: string): Nullable<Property>;
|
|
28
|
-
setProperty(name: string, value: any): void;
|
|
29
|
-
}
|
|
30
|
-
export declare const mixinPropertyStore: (target: any) => {
|
|
31
|
-
new (): {
|
|
32
|
-
[x: string]: any;
|
|
33
|
-
readonly __properties__: {
|
|
34
|
-
[key: string]: Property;
|
|
35
|
-
};
|
|
36
|
-
getProperties(): {
|
|
37
|
-
[key: string]: Property;
|
|
38
|
-
};
|
|
39
|
-
getProperty(name: string): Property;
|
|
40
|
-
setProperty(name: string, value: any): void;
|
|
41
|
-
};
|
|
42
|
-
[x: string]: any;
|
|
43
|
-
};
|
|
44
|
-
interface PropertyParams<T> {
|
|
45
|
-
defaultValue?: Nullable<T>;
|
|
46
|
-
propertiesName?: string;
|
|
47
|
-
beforeSetterName?: Nullable<string>;
|
|
48
|
-
units?: string;
|
|
49
|
-
minValue?: Nullable<number>;
|
|
50
|
-
maxValue?: Nullable<number>;
|
|
51
|
-
}
|
|
52
|
-
export declare function property<T>({ propertiesName, defaultValue, beforeSetterName, units, minValue, maxValue, }?: PropertyParams<T>): (target: any, propertyKey: string) => void;
|
|
53
|
-
export declare function propertyValidator<T>(propertyName: string, propertiesName?: string): (target: any, propertyKey: string, descriptor: PropertyDescriptor) => void;
|
|
54
|
-
export {};
|
package/lib/cjs/properties.js
DELETED
|
@@ -1,158 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.propertyValidator = exports.property = exports.mixinPropertyStore = exports.PropertyStore = exports.Property = exports.PropertySchema = void 0;
|
|
4
|
-
const bus_1 = require("./comms/bus");
|
|
5
|
-
const misc_1 = require("./misc");
|
|
6
|
-
class PropertySchema {
|
|
7
|
-
constructor(name, config) {
|
|
8
|
-
this.units = "";
|
|
9
|
-
this.defaultValue = null;
|
|
10
|
-
this.minValue = null;
|
|
11
|
-
this.maxValue = null;
|
|
12
|
-
this.beforeSetterName = null;
|
|
13
|
-
this.name = name;
|
|
14
|
-
this.beforeSetterName = misc_1.ifDefined(config.beforeSetterName);
|
|
15
|
-
this.units = misc_1.ifDefined(config.units);
|
|
16
|
-
this.defaultValue = misc_1.ifDefined(config.defaultValue);
|
|
17
|
-
this.minValue = misc_1.ifDefined(config.minValue);
|
|
18
|
-
this.maxValue = misc_1.ifDefined(config.maxValue);
|
|
19
|
-
}
|
|
20
|
-
validate(newValue) {
|
|
21
|
-
if (this.minValue != null && newValue < this.minValue)
|
|
22
|
-
return false;
|
|
23
|
-
if (this.maxValue != null && newValue > this.maxValue)
|
|
24
|
-
return false;
|
|
25
|
-
return true;
|
|
26
|
-
}
|
|
27
|
-
}
|
|
28
|
-
exports.PropertySchema = PropertySchema;
|
|
29
|
-
class Property {
|
|
30
|
-
constructor(schema) {
|
|
31
|
-
this.currentValue = null;
|
|
32
|
-
this.beforeSetterFunc = null;
|
|
33
|
-
this.schema = schema;
|
|
34
|
-
}
|
|
35
|
-
clone() {
|
|
36
|
-
const out = new Property(this.schema);
|
|
37
|
-
out.currentValue = this.currentValue;
|
|
38
|
-
return out;
|
|
39
|
-
}
|
|
40
|
-
get value() {
|
|
41
|
-
return this.currentValue;
|
|
42
|
-
}
|
|
43
|
-
setValue(instance, value) {
|
|
44
|
-
if (this.schema.beforeSetterName != null) {
|
|
45
|
-
if (this.beforeSetterFunc == null) {
|
|
46
|
-
const beforeSetterFunc = instance[this.schema.beforeSetterName];
|
|
47
|
-
if (beforeSetterFunc == null) {
|
|
48
|
-
throw new Error("Cannot find beforeSetter function: " + this.schema.beforeSetterName);
|
|
49
|
-
}
|
|
50
|
-
this.beforeSetterFunc = beforeSetterFunc.bind(instance);
|
|
51
|
-
}
|
|
52
|
-
if (this.beforeSetterFunc(value) == false) {
|
|
53
|
-
return false;
|
|
54
|
-
}
|
|
55
|
-
}
|
|
56
|
-
if (!this.schema.validate(value)) {
|
|
57
|
-
return false;
|
|
58
|
-
}
|
|
59
|
-
this.currentValue = value;
|
|
60
|
-
return true;
|
|
61
|
-
}
|
|
62
|
-
}
|
|
63
|
-
exports.Property = Property;
|
|
64
|
-
class PropertyStore {
|
|
65
|
-
constructor() {
|
|
66
|
-
this.__properties__ = {};
|
|
67
|
-
this.eventBus = bus_1.EventBus.getInstance();
|
|
68
|
-
}
|
|
69
|
-
getPropertyNames() {
|
|
70
|
-
return Object.keys(this.__properties__);
|
|
71
|
-
}
|
|
72
|
-
getProperty(name) {
|
|
73
|
-
this[name];
|
|
74
|
-
return this.__properties__[name] || null;
|
|
75
|
-
}
|
|
76
|
-
setProperty(name, value) {
|
|
77
|
-
if (this.__properties__[name]) {
|
|
78
|
-
const old = this.__properties__[name].value;
|
|
79
|
-
this.__properties__[name].setValue(this, value);
|
|
80
|
-
this.eventBus.emit("PropertyChange", {
|
|
81
|
-
name: name,
|
|
82
|
-
old: old,
|
|
83
|
-
current: value,
|
|
84
|
-
});
|
|
85
|
-
}
|
|
86
|
-
}
|
|
87
|
-
}
|
|
88
|
-
exports.PropertyStore = PropertyStore;
|
|
89
|
-
const mixinPropertyStore = (target) => {
|
|
90
|
-
return class extends target {
|
|
91
|
-
constructor() {
|
|
92
|
-
super(...arguments);
|
|
93
|
-
this.__properties__ = {};
|
|
94
|
-
}
|
|
95
|
-
getProperties() {
|
|
96
|
-
return this.__properties__;
|
|
97
|
-
}
|
|
98
|
-
getProperty(name) {
|
|
99
|
-
return this.__properties__[name];
|
|
100
|
-
}
|
|
101
|
-
setProperty(name, value) {
|
|
102
|
-
if (this.__properties__[name]) {
|
|
103
|
-
this.__properties__[name].setValue(this, value);
|
|
104
|
-
}
|
|
105
|
-
}
|
|
106
|
-
};
|
|
107
|
-
};
|
|
108
|
-
exports.mixinPropertyStore = mixinPropertyStore;
|
|
109
|
-
function ensureProperty(schema, instance, propertyKey, propertiesName = "__properties__") {
|
|
110
|
-
if (!instance[propertiesName]) {
|
|
111
|
-
throw new Error(`Property store (${propertiesName}) does not exist in target.`);
|
|
112
|
-
}
|
|
113
|
-
const propertiesMap = instance[propertiesName];
|
|
114
|
-
if (propertyKey in propertiesMap) {
|
|
115
|
-
return propertiesMap[propertyKey];
|
|
116
|
-
}
|
|
117
|
-
const property = (propertiesMap[propertyKey] = new Property(schema));
|
|
118
|
-
property.setValue(instance, schema.defaultValue);
|
|
119
|
-
return property;
|
|
120
|
-
}
|
|
121
|
-
function property({ propertiesName = "__properties__", defaultValue = null, beforeSetterName = null, units = "", minValue = null, maxValue = null, } = {}) {
|
|
122
|
-
return function (target, propertyKey) {
|
|
123
|
-
const root = target;
|
|
124
|
-
if (!(propertiesName in root)) {
|
|
125
|
-
root[propertiesName] = {};
|
|
126
|
-
}
|
|
127
|
-
const propertySchemas = root[propertiesName];
|
|
128
|
-
const newSchema = new PropertySchema(propertyKey, {
|
|
129
|
-
units: units,
|
|
130
|
-
beforeSetterName: beforeSetterName,
|
|
131
|
-
defaultValue: defaultValue,
|
|
132
|
-
minValue: minValue,
|
|
133
|
-
maxValue: maxValue,
|
|
134
|
-
});
|
|
135
|
-
if (propertyKey in propertySchemas) {
|
|
136
|
-
}
|
|
137
|
-
propertySchemas[propertyKey] = newSchema;
|
|
138
|
-
Object.defineProperty(target, propertyKey, {
|
|
139
|
-
get() {
|
|
140
|
-
const property = ensureProperty(newSchema, this, propertyKey, propertiesName);
|
|
141
|
-
return property.value;
|
|
142
|
-
},
|
|
143
|
-
set(newValue) {
|
|
144
|
-
const property = ensureProperty(newSchema, this, propertyKey, propertiesName);
|
|
145
|
-
property.setValue(this, newValue);
|
|
146
|
-
},
|
|
147
|
-
enumerable: true,
|
|
148
|
-
configurable: false,
|
|
149
|
-
});
|
|
150
|
-
};
|
|
151
|
-
}
|
|
152
|
-
exports.property = property;
|
|
153
|
-
function propertyValidator(propertyName, propertiesName = "__properties__") {
|
|
154
|
-
return function (target, propertyKey, descriptor) {
|
|
155
|
-
};
|
|
156
|
-
}
|
|
157
|
-
exports.propertyValidator = propertyValidator;
|
|
158
|
-
//# sourceMappingURL=properties.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"properties.js","sourceRoot":"","sources":["../../src/properties.ts"],"names":[],"mappings":";;;AACA,qCAAuC;AACvC,iCAAmC;AAEnC,MAAa,cAAc;IASzB,YAAY,IAAY,EAAE,MAAW;QAN9B,UAAK,GAAG,EAAE,CAAC;QACX,iBAAY,GAAQ,IAAI,CAAC;QACzB,aAAQ,GAAqB,IAAI,CAAC;QAClC,aAAQ,GAAqB,IAAI,CAAC;QAClC,qBAAgB,GAAqB,IAAI,CAAC;QAG/C,IAAI,CAAC,IAAI,GAAG,IAAI,CAAC;QACjB,IAAI,CAAC,gBAAgB,GAAG,gBAAS,CAAC,MAAM,CAAC,gBAAgB,CAAC,CAAC;QAC3D,IAAI,CAAC,KAAK,GAAG,gBAAS,CAAC,MAAM,CAAC,KAAK,CAAC,CAAC;QACrC,IAAI,CAAC,YAAY,GAAG,gBAAS,CAAC,MAAM,CAAC,YAAY,CAAC,CAAC;QACnD,IAAI,CAAC,QAAQ,GAAG,gBAAS,CAAC,MAAM,CAAC,QAAQ,CAAC,CAAC;QAC3C,IAAI,CAAC,QAAQ,GAAG,gBAAS,CAAC,MAAM,CAAC,QAAQ,CAAC,CAAC;IAC7C,CAAC;IAED,QAAQ,CAAC,QAAgB;QACvB,IAAI,IAAI,CAAC,QAAQ,IAAI,IAAI,IAAI,QAAQ,GAAG,IAAI,CAAC,QAAQ;YAAE,OAAO,KAAK,CAAC;QACpE,IAAI,IAAI,CAAC,QAAQ,IAAI,IAAI,IAAI,QAAQ,GAAG,IAAI,CAAC,QAAQ;YAAE,OAAO,KAAK,CAAC;QAEpE,OAAO,IAAI,CAAC;IACd,CAAC;CACF;AAxBD,wCAwBC;AAMD,MAAa,QAAQ;IAMnB,YAAY,MAAsB;QAH3B,iBAAY,GAAQ,IAAI,CAAC;QACzB,qBAAgB,GAAQ,IAAI,CAAC;QAGl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AAC,MAAM,EAAE,WAAW,EAAE;YACzC,GAAG;gBACD,MAAM,QAAQ,GAAG,cAAc,CAAC,SAAS,EAAE,IAAI,EAAE,WAAW,EAAE,cAAc,CAAC,CAAC;gBAC9E,OAAO,QAAQ,CAAC,KAAK,CAAC;YACxB,CAAC;YACD,GAAG,CAAC,QAAa;gBACf,MAAM,QAAQ,GAAG,cAAc,CAAC,SAAS,EAAE,IAAI,EAAE,WAAW,EAAE,cAAc,CAAC,CAAC;gBAC9E,QAAQ,CAAC,QAAQ,CAAC,IAAI,EAAE,QAAQ,CAAC,CAAC;YACpC,CAAC;YACD,UAAU,EAAE,IAAI;YAChB,YAAY,EAAE,KAAK;SACpB,CAAC,CAAC;IACL,CAAC,CAAC;AACJ,CAAC;AAvCD,4BAuCC;AAED,SAAgB,iBAAiB,CAAI,YAAoB,EAAE,cAAc,GAAG,gBAAgB;IAC1F,OAAO,UAAU,MAAW,EAAE,WAAmB,EAAE,UAA8B;IAGjF,CAAC,CAAC;AACJ,CAAC;AALD,8CAKC","sourcesContent":["import { Nullable } from \"./types\";\nimport { EventBus } from \"./comms/bus\";\nimport { ifDefined } from \"./misc\";\n\nexport class PropertySchema {\n // Name of the property\n public name: string;\n public units = \"\";\n public defaultValue: any = null;\n public minValue: Nullable<number> = null;\n public maxValue: Nullable<number> = null;\n public beforeSetterName: Nullable<string> = null;\n\n constructor(name: string, config: any) {\n this.name = name;\n this.beforeSetterName = ifDefined(config.beforeSetterName);\n this.units = ifDefined(config.units);\n this.defaultValue = ifDefined(config.defaultValue);\n this.minValue = ifDefined(config.minValue);\n this.maxValue = ifDefined(config.maxValue);\n }\n\n validate(newValue: number): boolean {\n if (this.minValue != null && newValue < this.minValue) return false;\n if (this.maxValue != null && newValue > this.maxValue) return false;\n // TODO - other validations\n return true;\n }\n}\n\n/**\n * Proprties are values required to fully resolve a component.\n * Like disk needs seek latency or capacity.\n */\nexport class Property {\n // Value of the property\n readonly schema: PropertySchema;\n public currentValue: any = null;\n public beforeSetterFunc: any = null;\n\n constructor(schema: PropertySchema) {\n this.schema = schema;\n }\n\n clone(): Property {\n const out = new Property(this.schema);\n out.currentValue = this.currentValue;\n return out;\n }\n\n get value() {\n return this.currentValue;\n }\n\n setValue(instance: any, value: any): boolean {\n if (this.schema.beforeSetterName != null) {\n if (this.beforeSetterFunc == null) {\n const beforeSetterFunc = instance[this.schema.beforeSetterName];\n if (beforeSetterFunc == null) {\n throw new Error(\"Cannot find beforeSetter function: \" + this.schema.beforeSetterName);\n }\n this.beforeSetterFunc = beforeSetterFunc.bind(instance);\n }\n if (this.beforeSetterFunc(value) == false) {\n // validation failed\n return false;\n }\n }\n if (!this.schema.validate(value)) {\n return false;\n }\n this.currentValue = value;\n return true;\n }\n}\n\nexport class PropertyStore {\n /**\n * The properties for this Element\n */\n readonly __properties__: { [key: string]: Property } = {};\n\n private eventBus = EventBus.getInstance();\n\n getPropertyNames(): string[] {\n // return Object.keys((this.constructor as any).__properties__);\n return Object.keys(this.__properties__);\n }\n\n getProperty(name: string): Nullable<Property> {\n (this as any)[name];\n return this.__properties__[name] || null;\n }\n\n setProperty(name: string, value: any): void {\n if (this.__properties__[name]) {\n const old = this.__properties__[name].value;\n this.__properties__[name].setValue(this, value);\n // TODO: Maybe need a fully qualified name here.\n this.eventBus.emit(\"PropertyChange\", {\n name: name,\n old: old,\n current: value,\n });\n }\n }\n}\n\nexport const mixinPropertyStore = (target: any) => {\n return class extends target {\n /**\n * The properties for this Element\n */\n readonly __properties__: { [key: string]: Property } = {};\n\n getProperties(): { [key: string]: Property } {\n return this.__properties__;\n }\n\n getProperty(name: string): Property {\n return this.__properties__[name];\n }\n\n setProperty(name: string, value: any): void {\n if (this.__properties__[name]) {\n this.__properties__[name].setValue(this, value);\n }\n }\n };\n};\n\ninterface PropertyParams<T> {\n defaultValue?: Nullable<T>;\n propertiesName?: string;\n beforeSetterName?: Nullable<string>;\n units?: string;\n minValue?: Nullable<number>;\n maxValue?: Nullable<number>;\n}\n\nfunction ensureProperty<T>(\n schema: PropertySchema,\n instance: any,\n propertyKey: string,\n propertiesName = \"__properties__\",\n): Property {\n if (!instance[propertiesName]) {\n throw new Error(`Property store (${propertiesName}) does not exist in target.`);\n }\n const propertiesMap = instance[propertiesName];\n if (propertyKey in propertiesMap) {\n return propertiesMap[propertyKey];\n }\n const property = (propertiesMap[propertyKey] = new Property(schema));\n property.setValue(instance, schema.defaultValue);\n return property;\n}\n\n/**\n * property is a decorator factory. It returns a decorator that can be applied to a property.\n * This decorator allows us to have some properties of an Element be treated specially (so it\n * can be reflected, configured/enumerated via UI). This decorator in a way makes our Element\n * attributes metadata-able so we dont have to duplicate a property object and an attribute\n * manually.\n */\nexport function property<T>({\n propertiesName = \"__properties__\",\n defaultValue = null,\n beforeSetterName = null,\n units = \"\",\n minValue = null,\n maxValue = null,\n}: PropertyParams<T> = {}) {\n return function (target: any, propertyKey: string) {\n const root = target; // .constructor;\n if (!(propertiesName in root)) {\n root[propertiesName] = {};\n }\n const propertySchemas = root[propertiesName];\n const newSchema = new PropertySchema(propertyKey, {\n units: units,\n beforeSetterName: beforeSetterName,\n defaultValue: defaultValue,\n minValue: minValue,\n maxValue: maxValue,\n });\n if (propertyKey in propertySchemas) {\n // throw new Error(\"Duplicate property: \" + propertyKey);\n }\n propertySchemas[propertyKey] = newSchema;\n\n Object.defineProperty(target, propertyKey, {\n get() {\n const property = ensureProperty(newSchema, this, propertyKey, propertiesName);\n return property.value;\n },\n set(newValue: any) {\n const property = ensureProperty(newSchema, this, propertyKey, propertiesName);\n property.setValue(this, newValue);\n },\n enumerable: true,\n configurable: false,\n });\n };\n}\n\nexport function propertyValidator<T>(propertyName: string, propertiesName = \"__properties__\") {\n return function (target: any, propertyKey: string, descriptor: PropertyDescriptor) {\n // const property = ensureProperty(this, propertyKey, null, propertiesName);\n // property.setValue(\n };\n}\n"]}
|
package/lib/esm/properties.d.ts
DELETED
|
@@ -1,54 +0,0 @@
|
|
|
1
|
-
import { Nullable } from "./types";
|
|
2
|
-
export declare class PropertySchema {
|
|
3
|
-
name: string;
|
|
4
|
-
units: string;
|
|
5
|
-
defaultValue: any;
|
|
6
|
-
minValue: Nullable<number>;
|
|
7
|
-
maxValue: Nullable<number>;
|
|
8
|
-
beforeSetterName: Nullable<string>;
|
|
9
|
-
constructor(name: string, config: any);
|
|
10
|
-
validate(newValue: number): boolean;
|
|
11
|
-
}
|
|
12
|
-
export declare class Property {
|
|
13
|
-
readonly schema: PropertySchema;
|
|
14
|
-
currentValue: any;
|
|
15
|
-
beforeSetterFunc: any;
|
|
16
|
-
constructor(schema: PropertySchema);
|
|
17
|
-
clone(): Property;
|
|
18
|
-
get value(): any;
|
|
19
|
-
setValue(instance: any, value: any): boolean;
|
|
20
|
-
}
|
|
21
|
-
export declare class PropertyStore {
|
|
22
|
-
readonly __properties__: {
|
|
23
|
-
[key: string]: Property;
|
|
24
|
-
};
|
|
25
|
-
private eventBus;
|
|
26
|
-
getPropertyNames(): string[];
|
|
27
|
-
getProperty(name: string): Nullable<Property>;
|
|
28
|
-
setProperty(name: string, value: any): void;
|
|
29
|
-
}
|
|
30
|
-
export declare const mixinPropertyStore: (target: any) => {
|
|
31
|
-
new (): {
|
|
32
|
-
[x: string]: any;
|
|
33
|
-
readonly __properties__: {
|
|
34
|
-
[key: string]: Property;
|
|
35
|
-
};
|
|
36
|
-
getProperties(): {
|
|
37
|
-
[key: string]: Property;
|
|
38
|
-
};
|
|
39
|
-
getProperty(name: string): Property;
|
|
40
|
-
setProperty(name: string, value: any): void;
|
|
41
|
-
};
|
|
42
|
-
[x: string]: any;
|
|
43
|
-
};
|
|
44
|
-
interface PropertyParams<T> {
|
|
45
|
-
defaultValue?: Nullable<T>;
|
|
46
|
-
propertiesName?: string;
|
|
47
|
-
beforeSetterName?: Nullable<string>;
|
|
48
|
-
units?: string;
|
|
49
|
-
minValue?: Nullable<number>;
|
|
50
|
-
maxValue?: Nullable<number>;
|
|
51
|
-
}
|
|
52
|
-
export declare function property<T>({ propertiesName, defaultValue, beforeSetterName, units, minValue, maxValue, }?: PropertyParams<T>): (target: any, propertyKey: string) => void;
|
|
53
|
-
export declare function propertyValidator<T>(propertyName: string, propertiesName?: string): (target: any, propertyKey: string, descriptor: PropertyDescriptor) => void;
|
|
54
|
-
export {};
|
package/lib/esm/properties.js
DELETED
|
@@ -1,149 +0,0 @@
|
|
|
1
|
-
import { EventBus } from "./comms/bus";
|
|
2
|
-
import { ifDefined } from "./misc";
|
|
3
|
-
export class PropertySchema {
|
|
4
|
-
constructor(name, config) {
|
|
5
|
-
this.units = "";
|
|
6
|
-
this.defaultValue = null;
|
|
7
|
-
this.minValue = null;
|
|
8
|
-
this.maxValue = null;
|
|
9
|
-
this.beforeSetterName = null;
|
|
10
|
-
this.name = name;
|
|
11
|
-
this.beforeSetterName = ifDefined(config.beforeSetterName);
|
|
12
|
-
this.units = ifDefined(config.units);
|
|
13
|
-
this.defaultValue = ifDefined(config.defaultValue);
|
|
14
|
-
this.minValue = ifDefined(config.minValue);
|
|
15
|
-
this.maxValue = ifDefined(config.maxValue);
|
|
16
|
-
}
|
|
17
|
-
validate(newValue) {
|
|
18
|
-
if (this.minValue != null && newValue < this.minValue)
|
|
19
|
-
return false;
|
|
20
|
-
if (this.maxValue != null && newValue > this.maxValue)
|
|
21
|
-
return false;
|
|
22
|
-
return true;
|
|
23
|
-
}
|
|
24
|
-
}
|
|
25
|
-
export class Property {
|
|
26
|
-
constructor(schema) {
|
|
27
|
-
this.currentValue = null;
|
|
28
|
-
this.beforeSetterFunc = null;
|
|
29
|
-
this.schema = schema;
|
|
30
|
-
}
|
|
31
|
-
clone() {
|
|
32
|
-
const out = new Property(this.schema);
|
|
33
|
-
out.currentValue = this.currentValue;
|
|
34
|
-
return out;
|
|
35
|
-
}
|
|
36
|
-
get value() {
|
|
37
|
-
return this.currentValue;
|
|
38
|
-
}
|
|
39
|
-
setValue(instance, value) {
|
|
40
|
-
if (this.schema.beforeSetterName != null) {
|
|
41
|
-
if (this.beforeSetterFunc == null) {
|
|
42
|
-
const beforeSetterFunc = instance[this.schema.beforeSetterName];
|
|
43
|
-
if (beforeSetterFunc == null) {
|
|
44
|
-
throw new Error("Cannot find beforeSetter function: " + this.schema.beforeSetterName);
|
|
45
|
-
}
|
|
46
|
-
this.beforeSetterFunc = beforeSetterFunc.bind(instance);
|
|
47
|
-
}
|
|
48
|
-
if (this.beforeSetterFunc(value) == false) {
|
|
49
|
-
return false;
|
|
50
|
-
}
|
|
51
|
-
}
|
|
52
|
-
if (!this.schema.validate(value)) {
|
|
53
|
-
return false;
|
|
54
|
-
}
|
|
55
|
-
this.currentValue = value;
|
|
56
|
-
return true;
|
|
57
|
-
}
|
|
58
|
-
}
|
|
59
|
-
export class PropertyStore {
|
|
60
|
-
constructor() {
|
|
61
|
-
this.__properties__ = {};
|
|
62
|
-
this.eventBus = EventBus.getInstance();
|
|
63
|
-
}
|
|
64
|
-
getPropertyNames() {
|
|
65
|
-
return Object.keys(this.__properties__);
|
|
66
|
-
}
|
|
67
|
-
getProperty(name) {
|
|
68
|
-
this[name];
|
|
69
|
-
return this.__properties__[name] || null;
|
|
70
|
-
}
|
|
71
|
-
setProperty(name, value) {
|
|
72
|
-
if (this.__properties__[name]) {
|
|
73
|
-
const old = this.__properties__[name].value;
|
|
74
|
-
this.__properties__[name].setValue(this, value);
|
|
75
|
-
this.eventBus.emit("PropertyChange", {
|
|
76
|
-
name: name,
|
|
77
|
-
old: old,
|
|
78
|
-
current: value,
|
|
79
|
-
});
|
|
80
|
-
}
|
|
81
|
-
}
|
|
82
|
-
}
|
|
83
|
-
export const mixinPropertyStore = (target) => {
|
|
84
|
-
return class extends target {
|
|
85
|
-
constructor() {
|
|
86
|
-
super(...arguments);
|
|
87
|
-
this.__properties__ = {};
|
|
88
|
-
}
|
|
89
|
-
getProperties() {
|
|
90
|
-
return this.__properties__;
|
|
91
|
-
}
|
|
92
|
-
getProperty(name) {
|
|
93
|
-
return this.__properties__[name];
|
|
94
|
-
}
|
|
95
|
-
setProperty(name, value) {
|
|
96
|
-
if (this.__properties__[name]) {
|
|
97
|
-
this.__properties__[name].setValue(this, value);
|
|
98
|
-
}
|
|
99
|
-
}
|
|
100
|
-
};
|
|
101
|
-
};
|
|
102
|
-
function ensureProperty(schema, instance, propertyKey, propertiesName = "__properties__") {
|
|
103
|
-
if (!instance[propertiesName]) {
|
|
104
|
-
throw new Error(`Property store (${propertiesName}) does not exist in target.`);
|
|
105
|
-
}
|
|
106
|
-
const propertiesMap = instance[propertiesName];
|
|
107
|
-
if (propertyKey in propertiesMap) {
|
|
108
|
-
return propertiesMap[propertyKey];
|
|
109
|
-
}
|
|
110
|
-
const property = (propertiesMap[propertyKey] = new Property(schema));
|
|
111
|
-
property.setValue(instance, schema.defaultValue);
|
|
112
|
-
return property;
|
|
113
|
-
}
|
|
114
|
-
export function property({ propertiesName = "__properties__", defaultValue = null, beforeSetterName = null, units = "", minValue = null, maxValue = null, } = {}) {
|
|
115
|
-
return function (target, propertyKey) {
|
|
116
|
-
const root = target;
|
|
117
|
-
if (!(propertiesName in root)) {
|
|
118
|
-
root[propertiesName] = {};
|
|
119
|
-
}
|
|
120
|
-
const propertySchemas = root[propertiesName];
|
|
121
|
-
const newSchema = new PropertySchema(propertyKey, {
|
|
122
|
-
units: units,
|
|
123
|
-
beforeSetterName: beforeSetterName,
|
|
124
|
-
defaultValue: defaultValue,
|
|
125
|
-
minValue: minValue,
|
|
126
|
-
maxValue: maxValue,
|
|
127
|
-
});
|
|
128
|
-
if (propertyKey in propertySchemas) {
|
|
129
|
-
}
|
|
130
|
-
propertySchemas[propertyKey] = newSchema;
|
|
131
|
-
Object.defineProperty(target, propertyKey, {
|
|
132
|
-
get() {
|
|
133
|
-
const property = ensureProperty(newSchema, this, propertyKey, propertiesName);
|
|
134
|
-
return property.value;
|
|
135
|
-
},
|
|
136
|
-
set(newValue) {
|
|
137
|
-
const property = ensureProperty(newSchema, this, propertyKey, propertiesName);
|
|
138
|
-
property.setValue(this, newValue);
|
|
139
|
-
},
|
|
140
|
-
enumerable: true,
|
|
141
|
-
configurable: false,
|
|
142
|
-
});
|
|
143
|
-
};
|
|
144
|
-
}
|
|
145
|
-
export function propertyValidator(propertyName, propertiesName = "__properties__") {
|
|
146
|
-
return function (target, propertyKey, descriptor) {
|
|
147
|
-
};
|
|
148
|
-
}
|
|
149
|
-
//# sourceMappingURL=properties.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"properties.js","sourceRoot":"","sources":["../../src/properties.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,QAAQ,EAAE,MAAM,aAAa,CAAC;AACvC,OAAO,EAAE,SAAS,EAAE,MAAM,QAAQ,CAAC;AAEnC,MAAM,OAAO,cAAc;IASzB,YAAY,IAAY,EAAE,MAAW;QAN9B,UAAK,GAAG,EAAE,CAAC;QACX,iBAAY,GAAQ,IAAI,CAAC;QACzB,aAAQ,GAAqB,IAAI,CAAC;QAClC,aAAQ,GAAqB,IAAI,CAAC;QAClC,qBAAgB,GAAqB,IAAI,CAAC;QAG/C,IAAI,CAAC,IAAI,GAAG,IAAI,CAAC;QACjB,IAAI,CAAC,gBAAgB,GAAG,SAAS,CAAC,MAAM,CAAC,gBAAgB,CAAC,CAAC;QAC3D,IAAI,CAAC,KAAK,GAAG,SAAS,CAAC,MAAM,CAAC,KAAK,CAAC,CAAC;QACrC,IAAI,CAAC,YAAY,GAAG,SAAS,CAAC,MAAM,CAAC,YAAY,CAAC,CAAC;QACnD,IAAI,CAAC,QAAQ,GAAG,SAAS,CAAC,MAAM,CAAC,QAAQ,CAAC,CAAC;QAC3C,IAAI,CAAC,QAAQ,GAAG,SAAS,CAAC,MAAM,CAAC,QAAQ,CAAC,CAAC;IAC7C,CAAC;IAED,QAAQ,CAAC,QAAgB;QACvB,IAAI,IAAI,CAAC,QAAQ,IAAI,IAAI,IAAI,QAAQ,GAAG,IAAI,CAAC,QAAQ;YAAE,OAAO,KAAK,CAAC;QACpE,IAAI,IAAI,CAAC,QAAQ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,YAAY;YAC1B,QAAQ,EAAE,QAAQ;YAClB,QAAQ,EAAE,QAAQ;SACnB,CAAC,CAAC;QACH,IAAI,WAAW,IAAI,eAAe,EAAE;SAEnC;QACD,eAAe,CAAC,WAAW,CAAC,GAAG,SAAS,CAAC;QAEzC,MAAM,CAAC,cAAc,CAAC,MAAM,EAAE,WAAW,EAAE;YACzC,GAAG;gBACD,MAAM,QAAQ,GAAG,cAAc,CAAC,SAAS,EAAE,IAAI,EAAE,WAAW,EAAE,cAAc,CAAC,CAAC;gBAC9E,OAAO,QAAQ,CAAC,KAAK,CAAC;YACxB,CAAC;YACD,GAAG,CAAC,QAAa;gBACf,MAAM,QAAQ,GAAG,cAAc,CAAC,SAAS,EAAE,IAAI,EAAE,WAAW,EAAE,cAAc,CAAC,CAAC;gBAC9E,QAAQ,CAAC,QAAQ,CAAC,IAAI,EAAE,QAAQ,CAAC,CAAC;YACpC,CAAC;YACD,UAAU,EAAE,IAAI;YAChB,YAAY,EAAE,KAAK;SACpB,CAAC,CAAC;IACL,CAAC,CAAC;AACJ,CAAC;AAED,MAAM,UAAU,iBAAiB,CAAI,YAAoB,EAAE,cAAc,GAAG,gBAAgB;IAC1F,OAAO,UAAU,MAAW,EAAE,WAAmB,EAAE,UAA8B;IAGjF,CAAC,CAAC;AACJ,CAAC","sourcesContent":["import { Nullable } from \"./types\";\nimport { EventBus } from \"./comms/bus\";\nimport { ifDefined } from \"./misc\";\n\nexport class PropertySchema {\n // Name of the property\n public name: string;\n public units = \"\";\n public defaultValue: any = null;\n public minValue: Nullable<number> = null;\n public maxValue: Nullable<number> = null;\n public beforeSetterName: Nullable<string> = null;\n\n constructor(name: string, config: any) {\n this.name = name;\n this.beforeSetterName = ifDefined(config.beforeSetterName);\n this.units = ifDefined(config.units);\n this.defaultValue = ifDefined(config.defaultValue);\n this.minValue = ifDefined(config.minValue);\n this.maxValue = ifDefined(config.maxValue);\n }\n\n validate(newValue: number): boolean {\n if (this.minValue != null && newValue < this.minValue) return false;\n if (this.maxValue != null && newValue > this.maxValue) return false;\n // TODO - other validations\n return true;\n }\n}\n\n/**\n * Proprties are values required to fully resolve a component.\n * Like disk needs seek latency or capacity.\n */\nexport class Property {\n // Value of the property\n readonly schema: PropertySchema;\n public currentValue: any = null;\n public beforeSetterFunc: any = null;\n\n constructor(schema: PropertySchema) {\n this.schema = schema;\n }\n\n clone(): Property {\n const out = new Property(this.schema);\n out.currentValue = this.currentValue;\n return out;\n }\n\n get value() {\n return this.currentValue;\n }\n\n setValue(instance: any, value: any): boolean {\n if (this.schema.beforeSetterName != null) {\n if (this.beforeSetterFunc == null) {\n const beforeSetterFunc = instance[this.schema.beforeSetterName];\n if (beforeSetterFunc == null) {\n throw new Error(\"Cannot find beforeSetter function: \" + this.schema.beforeSetterName);\n }\n this.beforeSetterFunc = beforeSetterFunc.bind(instance);\n }\n if (this.beforeSetterFunc(value) == false) {\n // validation failed\n return false;\n }\n }\n if (!this.schema.validate(value)) {\n return false;\n }\n this.currentValue = value;\n return true;\n }\n}\n\nexport class PropertyStore {\n /**\n * The properties for this Element\n */\n readonly __properties__: { [key: string]: Property } = {};\n\n private eventBus = EventBus.getInstance();\n\n getPropertyNames(): string[] {\n // return Object.keys((this.constructor as any).__properties__);\n return Object.keys(this.__properties__);\n }\n\n getProperty(name: string): Nullable<Property> {\n (this as any)[name];\n return this.__properties__[name] || null;\n }\n\n setProperty(name: string, value: any): void {\n if (this.__properties__[name]) {\n const old = this.__properties__[name].value;\n this.__properties__[name].setValue(this, value);\n // TODO: Maybe need a fully qualified name here.\n this.eventBus.emit(\"PropertyChange\", {\n name: name,\n old: old,\n current: value,\n });\n }\n }\n}\n\nexport const mixinPropertyStore = (target: any) => {\n return class extends target {\n /**\n * The properties for this Element\n */\n readonly __properties__: { [key: string]: Property } = {};\n\n getProperties(): { [key: string]: Property } {\n return this.__properties__;\n }\n\n getProperty(name: string): Property {\n return this.__properties__[name];\n }\n\n setProperty(name: string, value: any): void {\n if (this.__properties__[name]) {\n this.__properties__[name].setValue(this, value);\n }\n }\n };\n};\n\ninterface PropertyParams<T> {\n defaultValue?: Nullable<T>;\n propertiesName?: string;\n beforeSetterName?: Nullable<string>;\n units?: string;\n minValue?: Nullable<number>;\n maxValue?: Nullable<number>;\n}\n\nfunction ensureProperty<T>(\n schema: PropertySchema,\n instance: any,\n propertyKey: string,\n propertiesName = \"__properties__\",\n): Property {\n if (!instance[propertiesName]) {\n throw new Error(`Property store (${propertiesName}) does not exist in target.`);\n }\n const propertiesMap = instance[propertiesName];\n if (propertyKey in propertiesMap) {\n return propertiesMap[propertyKey];\n }\n const property = (propertiesMap[propertyKey] = new Property(schema));\n property.setValue(instance, schema.defaultValue);\n return property;\n}\n\n/**\n * property is a decorator factory. It returns a decorator that can be applied to a property.\n * This decorator allows us to have some properties of an Element be treated specially (so it\n * can be reflected, configured/enumerated via UI). This decorator in a way makes our Element\n * attributes metadata-able so we dont have to duplicate a property object and an attribute\n * manually.\n */\nexport function property<T>({\n propertiesName = \"__properties__\",\n defaultValue = null,\n beforeSetterName = null,\n units = \"\",\n minValue = null,\n maxValue = null,\n}: PropertyParams<T> = {}) {\n return function (target: any, propertyKey: string) {\n const root = target; // .constructor;\n if (!(propertiesName in root)) {\n root[propertiesName] = {};\n }\n const propertySchemas = root[propertiesName];\n const newSchema = new PropertySchema(propertyKey, {\n units: units,\n beforeSetterName: beforeSetterName,\n defaultValue: defaultValue,\n minValue: minValue,\n maxValue: maxValue,\n });\n if (propertyKey in propertySchemas) {\n // throw new Error(\"Duplicate property: \" + propertyKey);\n }\n propertySchemas[propertyKey] = newSchema;\n\n Object.defineProperty(target, propertyKey, {\n get() {\n const property = ensureProperty(newSchema, this, propertyKey, propertiesName);\n return property.value;\n },\n set(newValue: any) {\n const property = ensureProperty(newSchema, this, propertyKey, propertiesName);\n property.setValue(this, newValue);\n },\n enumerable: true,\n configurable: false,\n });\n };\n}\n\nexport function propertyValidator<T>(propertyName: string, propertiesName = \"__properties__\") {\n return function (target: any, propertyKey: string, descriptor: PropertyDescriptor) {\n // const property = ensureProperty(this, propertyKey, null, propertiesName);\n // property.setValue(\n };\n}\n"]}
|