wacom 20.0.2 → 20.0.3

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.
@@ -807,13 +807,61 @@ class CoreService {
807
807
  }
808
808
  // Angular Signals
809
809
  /**
810
- * Converts an array of objects to an array of Angular signals.
811
- * @template Document
812
- * @param {Document[]} arr - Array of objects to convert.
813
- * @returns {Signal<Document>[]} Array of signals wrapping each object.
810
+ * Converts an array of objects into an array of Angular signals.
811
+ * Optionally wraps specific fields of each object as individual signals.
812
+ *
813
+ * @template Document - The type of each object in the array.
814
+ * @param {Document[]} arr - Array of plain objects to convert into signals.
815
+ * @param {Record<string, (doc: Document) => unknown>} [updatableFields={}] -
816
+ * Optional map where keys are field names and values are functions that extract the initial value
817
+ * from the object. These fields will be turned into separate signals.
818
+ *
819
+ * @returns {Signal<Document>[]} An array where each item is a signal-wrapped object,
820
+ * optionally with individual fields also wrapped in signals.
821
+ *
822
+ * @example
823
+ * toSignalsArray(users, {
824
+ * name: (u) => u.name,
825
+ * score: (u) => u.score,
826
+ * });
827
+ */
828
+ toSignalsArray(arr, updatableFields = {}) {
829
+ return arr.map((obj) => {
830
+ if (Object.keys(updatableFields).length) {
831
+ const signalFields = {};
832
+ for (const key in updatableFields) {
833
+ signalFields[key] = signal(updatableFields[key](obj));
834
+ }
835
+ return signal({ ...obj, ...signalFields });
836
+ }
837
+ else {
838
+ return signal(obj);
839
+ }
840
+ });
841
+ }
842
+ /**
843
+ * Adds a new object to the signals array.
844
+ * Optionally wraps specific fields of the object as individual signals before wrapping the whole object.
845
+ *
846
+ * @template Document - The type of the object being added.
847
+ * @param {WritableSignal<Document>[]} signals - The signals array to append to.
848
+ * @param {Document} item - The object to wrap and push as a writable signal.
849
+ * @param {Record<string, (doc: Document) => unknown>} [updatableFields={}] -
850
+ * Optional map of fields to be wrapped as signals within the object.
851
+ *
852
+ * @returns {void}
814
853
  */
815
- toSignalsArray(arr) {
816
- return arr.map((obj) => signal(obj));
854
+ pushSignal(signals, item, updatableFields = {}) {
855
+ if (Object.keys(updatableFields).length) {
856
+ const fieldSignals = {};
857
+ for (const key in updatableFields) {
858
+ fieldSignals[key] = signal(updatableFields[key](item));
859
+ }
860
+ signals.push(signal({ ...item, ...fieldSignals }));
861
+ }
862
+ else {
863
+ signals.push(signal(item));
864
+ }
817
865
  }
818
866
  /**
819
867
  * Returns a generic trackBy function for *ngFor, tracking by the specified object field.
@@ -849,16 +897,6 @@ class CoreService {
849
897
  if (sig)
850
898
  sig.update(updater);
851
899
  }
852
- /**
853
- * Adds a new object as a writable signal to the signals array.
854
- * @template Document
855
- * @param {WritableSignal<Document>[]} signals - The signals array to modify.
856
- * @param {Document} item - The object to wrap and push as a writable signal.
857
- * @returns {void}
858
- */
859
- pushSignal(signals, item) {
860
- signals.push(signal(item));
861
- }
862
900
  /**
863
901
  * Removes the first signal from the array whose object's field matches the provided value.
864
902
  * @template Document