Signal Methods
TeamPlay signals come with a set of methods for interacting with the data they represent. These methods are available on all signals, whether they're created using $(), accessed through the root signal $, or returned by sub() or useSub().
get()
Retrieves the current value of the signal.
peek()
Retrieves the current value without tracking it for reactive rendering.
set(value)
Updates the value of the signal.
Note: set() is asynchronous and returns a Promise.
setReplace(value)
Replaces the current signal value without deep-diffing object or array branches.
Use this when stale object keys must be removed by replacing the whole value at the current path.
setNull(value)
Sets the value only when the current value is null or undefined.
If the current value is already non-nullish, setNull() is a no-op.
setDiff(value)
Replaces the current value unless the previous and next values are exactly equal.
setDiff() is not a recursive diff. Equivalent object and array values still replace the current value; only exact equality (===) and NaN vs NaN are skipped.
setDiffDeep(value)
Applies a recursive diff below the current signal path.
Stale object keys are removed recursively. Empty target objects are preserved, so await $filters.setDiffDeep({}) leaves $filters.get() as {} rather than undefined.
setEach(object)
Sets multiple object fields with per-key replace semantics.
Unlike assign(), setEach() does not treat null as delete. null is stored as null. undefined follows normal setReplace() semantics: private values keep the key with undefined, while public document subpaths are normalized to null.
del()
Deletes the value of the signal or removes an item from an array.
Note: del() is asynchronous and returns a Promise.
push(value)
Adds a value to the end of an array signal.
unshift(value)
Adds a value to the start of an array signal.
pop()
Removes and returns the last item from an array signal.
shift()
Removes and returns the first item from an array signal.
insert(index, values)
Inserts one or more values into an array signal at the specified index.
remove(index, howMany)
Removes one or more values from an array signal and returns the removed items.
move(from, to, howMany)
Moves one or more values within an array signal and returns the moved items.
increment(value)
Increments a numeric signal by the specified value (or by 1 if no value is provided).
stringInsert(index, text)
Inserts text into a string value at the specified index.
stringRemove(index, howMany)
Removes a substring from a string value.
add(value)
Adds a new item to a collection signal, automatically generating a unique ID.
add() accepts configured identity fields as a provided document ID. It also accepts legacy id and _id inputs.
If both are provided, they must be equal, otherwise add() throws.
getId()
Returns the usable string id for the document-like value represented by the current signal.
For direct public document signals and query item signals, TeamPlay already knows the document id from the path and returns that id directly. For nested document-like values, private values, and aggregation rows, TeamPlay first checks string _id and id fields on the current value. If neither exists, it falls back to the string leaf segment of the signal path.
If an explicit _id or id exists but is not a string, getId() returns undefined. The root signal and collection signals do not have ids and throw.
getIds()
Returns usable string ids for query or aggregation signals.
For query signals, ids come from the subscribed query metadata. For aggregation signals, ids are read from each row's string _id or id field. Rows without a usable string id are omitted, so the result is always a string[].
getExtra()
Returns extra metadata for query signals or rows for aggregation signals.
For query signals, this is equivalent to $query.extra.get(). For aggregation signals, it returns the same value as .get(). For ordinary signals, it returns undefined.
getCopy()
Returns a shallow copy of the current value.
Objects and arrays are copied at the top level only; nested objects keep their references.
getDeepCopy()
Returns a deep copy of the current value.
getDeepCopy() is useful when preparing an editable draft or snapshot that should not mutate the signal's live value.
getCollection()
Returns the collection name for the signal.
parent(levels = 1)
Returns the parent signal. If levels is greater than the path depth, returns the root signal.
leaf()
Returns the last path segment as a string.
path()
Returns the dot-separated path of the signal.
toString()
Returns a debug label for the signal. Primitive string coercion uses only the path, while toString() includes the Signal label:
getAssociations()
Returns association metadata registered on the signal's model class.
This is mostly useful for model-integration libraries and legacy ORM helpers.
assign(object)
Assigns multiple properties to a signal at once. This method iterates through the object's own properties and sets or deletes them on the signal.
Behavior:
- For non-null/undefined values: calls
.set(value)on the child signal (adds property if it doesn't exist) - For null/undefined values: calls
.del()on the child signal - Only assigns own properties (not inherited ones)
- Returns a Promise that resolves when all operations complete
Notes
- All methods that modify data (
set(),setReplace(),setNull(),setDiff(),setDiffDeep(),setEach(),del(),push(),pop(),increment(),add(),assign()) are asynchronous and return Promises. This ensures data consistency with the server. - The
get()method is synchronous and returns the current local value of the signal. - These methods can be chained on nested signals, e.g.,
$.users[userId].name.set('New Name'). - For public documents, configured identity fields are present in
get()results and match the document id.idFieldsdefaults to['_id']; attempts to change configured identity fields are ignored.