@axi-engine/utils 0.2.7 → 0.2.8

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/dist/index.d.mts CHANGED
@@ -263,6 +263,21 @@ declare class Emitter<T extends any[]> implements Subscribable<T> {
263
263
  */
264
264
  clear(): void;
265
265
  }
266
+ /**
267
+ * An Emitter that stores the last emitted value.
268
+ * New subscribers immediately receive the last value upon subscription.
269
+ */
270
+ declare class StateEmitter<T extends any[]> extends Emitter<T> {
271
+ private _lastValue;
272
+ constructor(initialValue?: T);
273
+ /**
274
+ * Gets the current value synchronously without subscribing.
275
+ */
276
+ get value(): T | undefined;
277
+ emit(...args: T): void;
278
+ subscribe(listener: (...args: T) => void): () => void;
279
+ clear(): void;
280
+ }
266
281
 
267
282
  /**
268
283
  * Type guard that checks if a value is a valid ScalarType.
@@ -424,4 +439,4 @@ declare class Registry<K extends PropertyKey, V> {
424
439
  clear(): void;
425
440
  }
426
441
 
427
- export { type AxiEngineConfig, type Constructor, type DataSink, type DataSource, type DataStorage, Emitter, type PathType, Registry, type ScalarType, type Subscribable, areArraysEqual, axiSettings, clampNumber, configure, ensurePathArray, ensurePathString, firstKeyOf, genArray, getPercentOf, getRandomElement, haveSameElements, isBoolean, isFunction, isNull, isNullOrUndefined, isNumber, isObject, isPercentageString, isPromise, isScalar, isSequentialStart, isString, isUndefined, last, randId, randInt, shuffleArray, throwError, throwIf, throwIfEmpty, unique };
442
+ export { type AxiEngineConfig, type Constructor, type DataSink, type DataSource, type DataStorage, Emitter, type PathType, Registry, type ScalarType, StateEmitter, type Subscribable, areArraysEqual, axiSettings, clampNumber, configure, ensurePathArray, ensurePathString, firstKeyOf, genArray, getPercentOf, getRandomElement, haveSameElements, isBoolean, isFunction, isNull, isNullOrUndefined, isNumber, isObject, isPercentageString, isPromise, isScalar, isSequentialStart, isString, isUndefined, last, randId, randInt, shuffleArray, throwError, throwIf, throwIfEmpty, unique };
package/dist/index.d.ts CHANGED
@@ -263,6 +263,21 @@ declare class Emitter<T extends any[]> implements Subscribable<T> {
263
263
  */
264
264
  clear(): void;
265
265
  }
266
+ /**
267
+ * An Emitter that stores the last emitted value.
268
+ * New subscribers immediately receive the last value upon subscription.
269
+ */
270
+ declare class StateEmitter<T extends any[]> extends Emitter<T> {
271
+ private _lastValue;
272
+ constructor(initialValue?: T);
273
+ /**
274
+ * Gets the current value synchronously without subscribing.
275
+ */
276
+ get value(): T | undefined;
277
+ emit(...args: T): void;
278
+ subscribe(listener: (...args: T) => void): () => void;
279
+ clear(): void;
280
+ }
266
281
 
267
282
  /**
268
283
  * Type guard that checks if a value is a valid ScalarType.
@@ -424,4 +439,4 @@ declare class Registry<K extends PropertyKey, V> {
424
439
  clear(): void;
425
440
  }
426
441
 
427
- export { type AxiEngineConfig, type Constructor, type DataSink, type DataSource, type DataStorage, Emitter, type PathType, Registry, type ScalarType, type Subscribable, areArraysEqual, axiSettings, clampNumber, configure, ensurePathArray, ensurePathString, firstKeyOf, genArray, getPercentOf, getRandomElement, haveSameElements, isBoolean, isFunction, isNull, isNullOrUndefined, isNumber, isObject, isPercentageString, isPromise, isScalar, isSequentialStart, isString, isUndefined, last, randId, randInt, shuffleArray, throwError, throwIf, throwIfEmpty, unique };
442
+ export { type AxiEngineConfig, type Constructor, type DataSink, type DataSource, type DataStorage, Emitter, type PathType, Registry, type ScalarType, StateEmitter, type Subscribable, areArraysEqual, axiSettings, clampNumber, configure, ensurePathArray, ensurePathString, firstKeyOf, genArray, getPercentOf, getRandomElement, haveSameElements, isBoolean, isFunction, isNull, isNullOrUndefined, isNumber, isObject, isPercentageString, isPromise, isScalar, isSequentialStart, isString, isUndefined, last, randId, randInt, shuffleArray, throwError, throwIf, throwIfEmpty, unique };
package/dist/index.js CHANGED
@@ -22,6 +22,7 @@ var index_exports = {};
22
22
  __export(index_exports, {
23
23
  Emitter: () => Emitter,
24
24
  Registry: () => Registry,
25
+ StateEmitter: () => StateEmitter,
25
26
  areArraysEqual: () => areArraysEqual,
26
27
  axiSettings: () => axiSettings,
27
28
  clampNumber: () => clampNumber,
@@ -200,6 +201,34 @@ var Emitter = class {
200
201
  this.listeners.clear();
201
202
  }
202
203
  };
204
+ var StateEmitter = class extends Emitter {
205
+ _lastValue;
206
+ constructor(initialValue) {
207
+ super();
208
+ this._lastValue = initialValue ?? void 0;
209
+ }
210
+ /**
211
+ * Gets the current value synchronously without subscribing.
212
+ */
213
+ get value() {
214
+ return this._lastValue;
215
+ }
216
+ emit(...args) {
217
+ this._lastValue = args;
218
+ super.emit(...args);
219
+ }
220
+ subscribe(listener) {
221
+ const unsubscribe = super.subscribe(listener);
222
+ if (!isUndefined(this._lastValue)) {
223
+ listener(...this._lastValue);
224
+ }
225
+ return unsubscribe;
226
+ }
227
+ clear() {
228
+ super.clear();
229
+ this._lastValue = void 0;
230
+ }
231
+ };
203
232
 
204
233
  // src/math.ts
205
234
  function clampNumber(val, min, max) {
@@ -288,6 +317,7 @@ var Registry = class {
288
317
  0 && (module.exports = {
289
318
  Emitter,
290
319
  Registry,
320
+ StateEmitter,
291
321
  areArraysEqual,
292
322
  axiSettings,
293
323
  clampNumber,
package/dist/index.mjs CHANGED
@@ -142,6 +142,34 @@ var Emitter = class {
142
142
  this.listeners.clear();
143
143
  }
144
144
  };
145
+ var StateEmitter = class extends Emitter {
146
+ _lastValue;
147
+ constructor(initialValue) {
148
+ super();
149
+ this._lastValue = initialValue ?? void 0;
150
+ }
151
+ /**
152
+ * Gets the current value synchronously without subscribing.
153
+ */
154
+ get value() {
155
+ return this._lastValue;
156
+ }
157
+ emit(...args) {
158
+ this._lastValue = args;
159
+ super.emit(...args);
160
+ }
161
+ subscribe(listener) {
162
+ const unsubscribe = super.subscribe(listener);
163
+ if (!isUndefined(this._lastValue)) {
164
+ listener(...this._lastValue);
165
+ }
166
+ return unsubscribe;
167
+ }
168
+ clear() {
169
+ super.clear();
170
+ this._lastValue = void 0;
171
+ }
172
+ };
145
173
 
146
174
  // src/math.ts
147
175
  function clampNumber(val, min, max) {
@@ -229,6 +257,7 @@ var Registry = class {
229
257
  export {
230
258
  Emitter,
231
259
  Registry,
260
+ StateEmitter,
232
261
  areArraysEqual,
233
262
  axiSettings,
234
263
  clampNumber,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@axi-engine/utils",
3
- "version": "0.2.7",
3
+ "version": "0.2.8",
4
4
  "description": "Core utility library for Axi Engine, providing common functions for arrays, math, type guards, and more.",
5
5
  "license": "MIT",
6
6
  "repository": {