wacom 20.0.2 → 20.0.5

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,74 @@ 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 a plain object into a signal-wrapped object.
811
+ * Optionally wraps specific fields of the object as individual signals,
812
+ * and merges them into the returned signal for fine-grained reactivity.
813
+ *
814
+ * @template Document - The type of the object being wrapped.
815
+ * @param {Document} document - The plain object to wrap into a signal.
816
+ * @param {Record<string, (doc: Document) => unknown>} [updatableFields={}] -
817
+ * Optional map where each key is a field name and the value is a function
818
+ * to extract the initial value for that field. These fields will be wrapped
819
+ * as separate signals and embedded in the returned object.
820
+ *
821
+ * @returns {Signal<Document>} A signal-wrapped object, possibly containing
822
+ * nested field signals for more granular control.
823
+ *
824
+ * @example
825
+ * const user = { _id: '1', name: 'Alice', score: 42 };
826
+ * const sig = toSignal(user, { score: (u) => u.score });
827
+ * console.log(sig().name); // 'Alice'
828
+ * console.log(sig().score()); // 42 — field is now a signal
829
+ */
830
+ toSignal(document, updatableFields = {}) {
831
+ if (Object.keys(updatableFields).length) {
832
+ const signalFields = {};
833
+ for (const key in updatableFields) {
834
+ signalFields[key] = signal(updatableFields[key](document));
835
+ }
836
+ return signal({ ...document, ...signalFields });
837
+ }
838
+ else {
839
+ return signal(document);
840
+ }
841
+ }
842
+ /**
843
+ * Converts an array of objects into an array of Angular signals.
844
+ * Optionally wraps specific fields of each object as individual signals.
845
+ *
846
+ * @template Document - The type of each object in the array.
847
+ * @param {Document[]} arr - Array of plain objects to convert into signals.
848
+ * @param {Record<string, (doc: Document) => unknown>} [updatableFields={}] -
849
+ * Optional map where keys are field names and values are functions that extract the initial value
850
+ * from the object. These fields will be turned into separate signals.
851
+ *
852
+ * @returns {Signal<Document>[]} An array where each item is a signal-wrapped object,
853
+ * optionally with individual fields also wrapped in signals.
854
+ *
855
+ * @example
856
+ * toSignalsArray(users, {
857
+ * name: (u) => u.name,
858
+ * score: (u) => u.score,
859
+ * });
860
+ */
861
+ toSignalsArray(arr, updatableFields = {}) {
862
+ return arr.map((obj) => this.toSignal(obj, updatableFields));
863
+ }
864
+ /**
865
+ * Adds a new object to the signals array.
866
+ * Optionally wraps specific fields of the object as individual signals before wrapping the whole object.
867
+ *
868
+ * @template Document - The type of the object being added.
869
+ * @param {Signal<Document>[]} signals - The signals array to append to.
870
+ * @param {Document} item - The object to wrap and push as a signal.
871
+ * @param {Record<string, (doc: Document) => unknown>} [updatableFields={}] -
872
+ * Optional map of fields to be wrapped as signals within the object.
873
+ *
874
+ * @returns {void}
814
875
  */
815
- toSignalsArray(arr) {
816
- return arr.map((obj) => signal(obj));
876
+ pushSignal(signals, item, updatableFields = {}) {
877
+ signals.push(this.toSignal(item, updatableFields));
817
878
  }
818
879
  /**
819
880
  * Returns a generic trackBy function for *ngFor, tracking by the specified object field.
@@ -849,16 +910,6 @@ class CoreService {
849
910
  if (sig)
850
911
  sig.update(updater);
851
912
  }
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
913
  /**
863
914
  * Removes the first signal from the array whose object's field matches the provided value.
864
915
  * @template Document