diff --git a/tansu.aswritable.md b/tansu.aswritable.md new file mode 100644 index 0000000..b8ecf55 --- /dev/null +++ b/tansu.aswritable.md @@ -0,0 +1,27 @@ + + +[Home](./index.md) > [@amadeus-it-group/tansu](./tansu.md) > [asWritable](./tansu.aswritable.md) + +## asWritable() function + +Returns a wrapper (for the given store) which only exposes the [WritableSignal](./tansu.writablesignal.md) interface. When the value is changed from the given wrapper, the provided set function is called. + +**Signature:** + +```typescript +export declare function asWritable(store: StoreInput, set?: WritableSignal['set']): WritableSignal; +``` + +## Parameters + +| Parameter | Type | Description | +| --- | --- | --- | +| store | [StoreInput](./tansu.storeinput.md)<T> | store to wrap | +| set | [WritableSignal](./tansu.writablesignal.md)<T, W>\['set'\] | _(Optional)_ function that will be called when the value is changed from the wrapper (through the [set](./tansu.writable.set.md) or the [update](./tansu.writable.update.md) function). If set is not specified, a noop function is used (so the value of the store cannot be changed from the returned wrapper). | + +**Returns:** + +[WritableSignal](./tansu.writablesignal.md)<T, W> + +A wrapper which only exposes the [WritableSignal](./tansu.writablesignal.md) interface. + diff --git a/tansu.aswritable_1.md b/tansu.aswritable_1.md new file mode 100644 index 0000000..2846299 --- /dev/null +++ b/tansu.aswritable_1.md @@ -0,0 +1,27 @@ + + +[Home](./index.md) > [@amadeus-it-group/tansu](./tansu.md) > [asWritable](./tansu.aswritable_1.md) + +## asWritable() function + +Returns a wrapper (for the given store) which only exposes the [WritableSignal](./tansu.writablesignal.md) interface and also adds the given extra properties on the returned object. + +**Signature:** + +```typescript +export declare function asWritable(store: StoreInput, extraProps: U & Partial, 'set' | 'update'>>): WritableSignal & Omit>; +``` + +## Parameters + +| Parameter | Type | Description | +| --- | --- | --- | +| store | [StoreInput](./tansu.storeinput.md)<T> | store to wrap | +| extraProps | U & Partial<Pick<[WritableSignal](./tansu.writablesignal.md)<T, W>, 'set' \| 'update'>> | object containing the extra properties to add on the returned object, and optionally the [set](./tansu.writable.set.md) and the [update](./tansu.writable.update.md) function of the [WritableSignal](./tansu.writablesignal.md) interface. If the set function is not specified, a noop function is used. If the update function is not specified, a default function that calls set is used. | + +**Returns:** + +[WritableSignal](./tansu.writablesignal.md)<T, W> & Omit<U, keyof [WritableSignal](./tansu.writablesignal.md)<T, W>> + +A wrapper which only exposes the [WritableSignal](./tansu.writablesignal.md) interface and the given extra properties. + diff --git a/tansu.equal.md b/tansu.equal.md new file mode 100644 index 0000000..ce7d3e0 --- /dev/null +++ b/tansu.equal.md @@ -0,0 +1,13 @@ + + +[Home](./index.md) > [@amadeus-it-group/tansu](./tansu.md) > [equal](./tansu.equal.md) + +## equal variable + +Default implementation of the equal function used by tansu when a store changes, to know if listeners need to be notified. Returns false if `a` is a function or an object, or if `a` and `b` are different according to `Object.is`. Otherwise, returns true. + +**Signature:** + +```typescript +equal: (a: T, b: T) => boolean +``` diff --git a/tansu.md b/tansu.md index 8392f68..06c6218 100644 --- a/tansu.md +++ b/tansu.md @@ -19,6 +19,8 @@ tansu is a lightweight, push-based state management library. It borrows the idea | --- | --- | | [asReadable(store)](./tansu.asreadable.md) | Returns a wrapper (for the given store) which only exposes the [ReadableSignal](./tansu.readablesignal.md) interface. This converts any [StoreInput](./tansu.storeinput.md) to a [ReadableSignal](./tansu.readablesignal.md) and exposes the store as read-only. | | [asReadable(store, extraProp)](./tansu.asreadable_1.md) | Returns a wrapper (for the given store) which only exposes the [ReadableSignal](./tansu.readablesignal.md) interface and also adds the given extra properties on the returned object. | +| [asWritable(store, set)](./tansu.aswritable.md) | Returns a wrapper (for the given store) which only exposes the [WritableSignal](./tansu.writablesignal.md) interface. When the value is changed from the given wrapper, the provided set function is called. | +| [asWritable(store, extraProps)](./tansu.aswritable_1.md) | Returns a wrapper (for the given store) which only exposes the [WritableSignal](./tansu.writablesignal.md) interface and also adds the given extra properties on the returned object. | | [computed(fn, options)](./tansu.computed.md) | Creates a store whose value is computed by the provided function. | | [derived(stores, options, initialValue)](./tansu.derived.md) | A convenience function to create a new store with a state computed from the latest values of dependent stores. Each time the state of one of the dependent stores changes, a provided derive function is called to compute a new, derived state. | | [derived(stores, options, initialValue)](./tansu.derived_1.md) | | @@ -45,6 +47,7 @@ tansu is a lightweight, push-based state management library. It borrows the idea | Variable | Description | | --- | --- | | [batch](./tansu.batch.md) | Batches multiple changes to stores while calling the provided function, preventing derived stores from updating until the function returns, to avoid unnecessary recomputations. | +| [equal](./tansu.equal.md) | Default implementation of the equal function used by tansu when a store changes, to know if listeners need to be notified. Returns false if a is a function or an object, or if a and b are different according to Object.is. Otherwise, returns true. | | [get](./tansu.get.md) | A utility function to get the current value from a given store. It works by subscribing to a store, capturing the value (synchronously) and unsubscribing just after. | | [symbolObservable](./tansu.symbolobservable.md) | Symbol used in [InteropObservable](./tansu.interopobservable.md) allowing any object to expose an observable. | | [untrack](./tansu.untrack.md) | Stops the tracking of dependencies made by [computed()](./tansu.computed.md) and calls the provided function. After the function returns, the tracking of dependencies continues as before. |