Skip to content

Commit

Permalink
fix: clarify TS Docs for better DX
Browse files Browse the repository at this point in the history
Fixes #2936
  • Loading branch information
taefi committed Dec 20, 2024
1 parent ad2c774 commit fdc7b88
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 3 deletions.
7 changes: 5 additions & 2 deletions packages/ts/react-signals/src/FullStackSignal.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,10 @@ interface VaadinGlobal {
const ENDPOINT = 'SignalsHandler';

/**
* A return type for signal operations.
* A return type for signal operations that exposes a `result` property of type
* Promise, that resolves when the operation is completed. It allows defining
* callbacks to be run after the operation is completed, or error handling when
* the operation fails.
*/
export type Operation = {
result: Promise<void>;
Expand Down Expand Up @@ -230,7 +233,7 @@ export abstract class FullStackSignal<T> extends DependencyTrackingSignal<T> {
}
>();

// creates the obejct to be returned by operations to allow defining callbacks
// creates the object to be returned by operations to allow defining callbacks
protected [$createOperation]({ id, promise }: { id?: string; promise?: Promise<void> }): Operation {
const thens = this.#operationPromises;
const promises: Array<Promise<void>> = [];
Expand Down
2 changes: 2 additions & 0 deletions packages/ts/react-signals/src/ListSignal.ts
Original file line number Diff line number Diff line change
Expand Up @@ -151,6 +151,7 @@ export class ListSignal<T> extends CollectionSignal<ReadonlyArray<ValueSignal<T>
/**
* Inserts a new value at the end of the list.
* @param value - The value to insert.
* @returns An operation object that allows to perform additional actions.
*/
insertLast(value: T): Operation {
const event = createInsertLastStateEvent(value);
Expand All @@ -161,6 +162,7 @@ export class ListSignal<T> extends CollectionSignal<ReadonlyArray<ValueSignal<T>
/**
* Removes the given item from the list.
* @param item - The item to remove.
* @returns An operation object that allows to perform additional actions.
*/
remove(item: ValueSignal<T>): Operation {
const entryToRemove = this.#values.get(item.id);
Expand Down
4 changes: 3 additions & 1 deletion packages/ts/react-signals/src/ValueSignal.ts
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ export class ValueSignal<T> extends FullStackSignal<T> {
* `replace` method instead.
*
* @param value - The new value.
* @returns An operation object that allows to perform additional actions.
*/
set(value: T): Operation {
const { parentClientSignalId } = this.server.config;
Expand Down Expand Up @@ -81,7 +82,8 @@ export class ValueSignal<T> extends FullStackSignal<T> {
*
* @param callback - The function that is applied on the current value to
* produce the new value.
* @returns An operation object that allows to perform additional actions, including cancellation.
* @returns An operation object that allows to perform additional actions,
* including cancellation.
*/
update(callback: (value: T) => T): OperationSubscription {
const newValue = callback(this.value);
Expand Down

0 comments on commit fdc7b88

Please sign in to comment.