universal-stores
- DerivedStoreConfig
- EqualityComparator
- Getter
- ReactiveRoot
- ReadonlyStore
- Setter
- StartHandler
- StopHandler
- Store
- StoreConfig
- Subscriber
- Unsubscribe
- Update
- Updater
Ƭ DerivedStoreConfig<T
>: Object
Configurations for derived stores.
Name |
---|
T |
Name | Type | Description |
---|---|---|
comparator? |
EqualityComparator <T > |
(optional, defaults to (a, b) => a === b ) a function that's used to determine if the current value of the store value is different from the one being set and thus if the store needs to be updated and the subscribers notified. |
Ƭ EqualityComparator<T
>: (a
: T
, b
: T
) => boolean
Name |
---|
T |
▸ (a
, b
): boolean
A comparison function used to optimize subscribers notifications. Used in Store
Name | Type |
---|---|
a |
T |
b |
T |
boolean
Ƭ Getter<T
>: () => T
Name |
---|
T |
▸ (): T
A generic getter function. Used in Store
T
Ƭ ReactiveRoot: Object
A reactive root provides a scope for all the effect it contains. This scope can then be destroyed (and all the effect cleaned up) by calling the dispose method.
Name | Type |
---|---|
dispose |
() => void |
makeEffect |
(fn : () => void | () => void ) => void |
Ƭ ReadonlyStore<T
>: Object
A store that can have subscribers and emit values to them. It also provides the current value upon subscription. It's readonly in the sense that it doesn't provide direct set/update methods, unlike Store, therefore its value can only be changed by a StartHandler (see also makeReadonlyStore).
Name |
---|
T |
Name | Type |
---|---|
content |
() => T |
nOfSubscriptions |
() => number |
subscribe |
(subscriber : Subscriber <T >) => Unsubscribe |
watch |
() => T |
Ƭ Setter<T
>: (newValue
: T
) => void
Name |
---|
T |
▸ (newValue
): void
A generic setter function. Used in Store
Name | Type |
---|---|
newValue |
T |
void
Ƭ StartHandler<T
>: (set
: Setter
<T
>) => StopHandler
| void
Name |
---|
T |
▸ (set
): StopHandler
| void
A function that gets called once a store gets at least one subscriber. Used in Store
Name | Type |
---|---|
set |
Setter <T > |
StopHandler
| void
Ƭ StopHandler: () => void
▸ (): void
A function that gets called once a store reaches 0 subscribers. Used in Store
void
Ƭ Store<T
>: ReadonlyStore
<T
> & { set
: (v
: T
) => void
; update
: (updater
: Updater
<T
>) => void
}
A store that can have subscribers and emit values to them. It also provides the current value upon subscription.
Name |
---|
T |
Ƭ StoreConfig<T
>: Object
Configurations for Store and ReadonlyStore.
Name |
---|
T |
Name | Type | Description |
---|---|---|
comparator? |
EqualityComparator <T > |
(optional, defaults to (a, b) => a === b ) a function that's used to determine if the current value of the store value is different from the one being set and thus if the store needs to be updated and the subscribers notified. |
start? |
StartHandler <T > |
(optional) a StartHandler that will get called once there is at least one subscriber to this store. |
Ƭ Subscriber<T
>: (current
: T
) => void
Name |
---|
T |
▸ (current
): void
A generic subscriber that takes a value emitted by a signal as its only parameter.
Name | Type |
---|---|
current |
T |
void
node_modules/@cdellacqua/signals/dist/index.d.ts:2
Ƭ Unsubscribe: () => void
▸ (): void
A function that's used to unsubscribe a subscriber from a signal.
void
node_modules/@cdellacqua/signals/dist/index.d.ts:4
Ƭ Update<T
>: (updater
: (current
: T
) => T
) => void
Name |
---|
T |
▸ (updater
): void
A generic update function. Used in Store
Name | Type |
---|---|
updater |
(current : T ) => T |
void
Ƭ Updater<T
>: (current
: T
) => T
Name |
---|
T |
▸ (current
): T
A generic updater function. Used in Store
Name | Type |
---|---|
current |
T |
T
• Const
storeRuntime: Object
Name | Type |
---|---|
storeCount |
number |
▸ batchEffects(action
): void
Run the passed function, enqueueing and deduplicating the effects it may trigger, in order to run them just at the end to avoid "glitches".
NOTE: batchEffects can be nested, all updates will automatically be accumulated in the outmost "batch" before the effects are executed.
Name | Type | Description |
---|---|---|
action |
() => void |
A function that directly or indirectly updates one or more stores. |
void
▸ makeDerivedStore<TIn
, TOut
>(readonlyStore
, map
, config?
): ReadonlyStore
<TOut
>
Create a derived store.
Example usage:
const source$ = makeStore(10);
const derived$ = makeDerivedStore(source$, (v) => v * 2);
source$.subscribe((v) => console.log(v)); // prints 10
derived$.subscribe((v) => console.log(v)); // prints 20
source$.set(16); // triggers both console.logs, printing 16 and 32
Name |
---|
TIn |
TOut |
Name | Type | Description |
---|---|---|
readonlyStore |
ReadonlyStore <TIn > |
a store or readonly store. |
map |
(value : TIn ) => TOut |
a function that takes the current value of the source store and maps it to another value. |
config? |
DerivedStoreConfig <TOut > |
a DerivedStoreConfig which contains configuration information such as a value comparator to avoid needless notifications to subscribers. |
ReadonlyStore
<TOut
>
▸ makeDerivedStore<TIn
, TOut
>(readonlyStores
, map
, config?
): ReadonlyStore
<TOut
>
Create a derived store from multiple sources.
Example usage:
const source1$ = makeStore(10);
const source2$ = makeStore(-10);
const derived$ = makeDerivedStore([source1$, source2$], ([v1, v2]) => v1 + v2);
source1$.subscribe((v) => console.log(v)); // prints 10
source2$.subscribe((v) => console.log(v)); // prints -10
derived$.subscribe((v) => console.log(v)); // prints 0
source1$.set(11); // prints 11 (first console.log) and 1 (third console.log)
source2$.set(9); // prints 9 (second console.log) and 20 (third console.log)
Name | Type |
---|---|
TIn |
extends unknown [] | [unknown , ...unknown[]] |
TOut |
TOut |
Name | Type | Description |
---|---|---|
readonlyStores |
{ [K in string | number | symbol]: ReadonlyStore<TIn[K]> } | an array of stores or readonly stores. |
map |
(value : { [K in string | number | symbol]: TIn[K] }) => TOut |
a function that takes the current value of all the source stores and maps it to another value. |
config? |
DerivedStoreConfig <TOut > |
a DerivedStoreConfig which contains configuration information such as a value comparator to avoid needless notifications to subscribers. |
ReadonlyStore
<TOut
>
▸ makeDerivedStore<TIn
, TOut
>(readonlyStores
, map
, config?
): ReadonlyStore
<TOut
>
Create a derived store from multiple sources.
Example usage:
const source1$ = makeStore(10);
const source2$ = makeStore(-10);
const derived$ = makeDerivedStore({v1: source1$, v2: source2$}, ({v1, v2}) => v1 + v2);
source1$.subscribe((v) => console.log(v)); // prints 10
source2$.subscribe((v) => console.log(v)); // prints -10
derived$.subscribe((v) => console.log(v)); // prints 0
source1$.set(11); // prints 11 (first console.log) and 1 (third console.log)
source2$.set(9); // prints 9 (second console.log) and 20 (third console.log)
Name |
---|
TIn |
TOut |
Name | Type | Description |
---|---|---|
readonlyStores |
{ [K in string | number | symbol]: ReadonlyStore<TIn[K]> } | an array of stores or readonly stores. |
map |
(value : { [K in string | number | symbol]: TIn[K] }) => TOut |
a function that takes the current value of all the source stores and maps it to another value. |
config? |
DerivedStoreConfig <TOut > |
a DerivedStoreConfig which contains configuration information such as a value comparator to avoid needless notifications to subscribers. |
ReadonlyStore
<TOut
>
▸ makeReactiveRoot(): ReactiveRoot
Create a ReactiveRoot, providing a makeEffect and a dispose function.
▸ makeReadonlyStore<T
>(initialValue
, start?
): ReadonlyStore
<T
>
Make a store of type T.
Example usage:
let value = 0;
const store$ = makeReadonlyStore(value, (set) => {
value++;
set(value);
});
console.log(store$.content()); // 1
store$.subscribe((v) => console.log(v)); // immediately prints 2
console.log(store$.content()); // 2
Name |
---|
T |
Name | Type | Description |
---|---|---|
initialValue |
undefined | T |
the initial value of the store. |
start? |
StartHandler <T > |
a StartHandler that will get called once there is at least one subscriber to this store. |
a ReadonlyStore
▸ makeReadonlyStore<T
>(initialValue
, config?
): ReadonlyStore
<T
>
Make a store of type T.
Example usage:
const store$ = makeReadonlyStore({prop: 'some value'}, {
comparator: (a, b) => a.prop === b.prop,
start: (set) => {
// ...
},
});
Name |
---|
T |
Name | Type | Description |
---|---|---|
initialValue |
undefined | T |
the initial value of the store. |
config? |
StoreConfig <T > |
a StoreConfig which contains configuration information such as a value comparator to avoid needless notifications to subscribers and a StartHandler. |
a ReadonlyStore
▸ makeReadonlyStore<T
>(initialValue
, startOrConfig?
): ReadonlyStore
<T
>
Make a store of type T.
Example usage:
let value = 0;
const store$ = makeReadonlyStore(value, (set) => {
value++;
set(value);
});
console.log(store$.content()); // 1
store$.subscribe((v) => console.log(v)); // immediately prints 2
console.log(store$.content()); // 2
Name |
---|
T |
Name | Type | Description |
---|---|---|
initialValue |
undefined | T |
the initial value of the store. |
startOrConfig? |
StartHandler <T > | StoreConfig <T > |
a StartHandler or a StoreConfig which contains configuration information such as a value comparator to avoid needless notifications to subscribers and a StartHandler. |
a ReadonlyStore
▸ makeStore<T
>(initialValue
, start?
): Store
<T
>
Make a store of type T.
Example usage:
const store$ = makeStore(0);
console.log(store$.content()); // 0
store$.subscribe((v) => console.log(v));
store$.set(10); // will trigger the above console log, printing 10
Name |
---|
T |
Name | Type | Description |
---|---|---|
initialValue |
undefined | T |
the initial value of the store. |
start? |
StartHandler <T > |
a StartHandler that will get called once there is at least one subscriber to this store. |
Store
<T
>
a Store
▸ makeStore<T
>(initialValue
, config?
): Store
<T
>
Make a store of type T.
Example usage:
const store$ = makeStore(0);
console.log(store$.content()); // 0
store$.subscribe((v) => console.log(v));
store$.set(10); // will trigger the above console log, printing 10
Name |
---|
T |
Name | Type | Description |
---|---|---|
initialValue |
undefined | T |
the initial value of the store. |
config? |
StoreConfig <T > |
a StoreConfig which contains configuration information such as a value comparator to avoid needless notifications to subscribers and a StartHandler. |
Store
<T
>
a Store
▸ makeStore<T
>(initialValue
, startOrConfig?
): Store
<T
>
Make a store of type T.
Example usage:
const store$ = makeStore(0);
console.log(store$.content()); // 0
store$.subscribe((v) => console.log(v));
store$.set(10); // will trigger the above console log, printing 10
Name |
---|
T |
Name | Type | Description |
---|---|---|
initialValue |
undefined | T |
the initial value of the store. |
startOrConfig? |
StartHandler <T > | StoreConfig <T > |
a StartHandler or a StoreConfig which contains configuration information such as a value comparator to avoid needless notifications to subscribers and a StartHandler. |
Store
<T
>
a Store