Domain
Domain is a namespace for your events, stores and effects.
Domain can subscribe to event, effect, store or nested domain creation with onCreateEvent
, onCreateStore
, onCreateEffect
, onCreateDomain
methods.
It is useful for logging or other side effects.
#
Unit creatorssince
effector 20.7.0
createEvent(name?)
#
Arguments
name
? (string): event name
Returns
Event: New event
createEffect(handler?)
#
Creates an effect with given handler
Arguments
handler
? (Function): function to handle effect calls, also can be set withuse(handler)
Returns
Effect: A container for async function.
since
effector 21.3.0
createEffect(name?)
#
Arguments
name
? (string): effect name
Returns
Effect: A container for async function.
createStore(defaultState)
#
Arguments
defaultState
(State): store default state
Returns
Store: New store
createDomain(name?)
#
Arguments
name
? (string): domain name
Returns
Domain: New domain
history
#
Contains mutable read-only sets of units inside domain.
#
Formulae- When any kind of units created inside domain, it appears in set with the name of type(stores, events, domains, effects) in the same order as created
since
effector 20.3.0
#
Aliasesevent(name?)
#
An alias for domain.createEvent
effect(name?)
#
An alias for domain.createEffect
store(defaultState)
#
An alias for domain.createStore
domain(name?)
#
An alias for domain.createDomain
#
Domain hooksonCreateEvent(hook)
#
#
Formulae- Function passed to
onCreateEvent
called every time, as new event created indomain
- Function called with
event
as first argument - Result of function call is ignored
Arguments
hook
(Watcher): A function that receives Event and will be called during every domain.createEvent call
Returns
Subscription: Unsubscribe function.
#
ExampleonCreateEffect(hook)
#
#
Formulae- Function passed to
onCreateEffect
called every time, as new effect created indomain
- Function called with
effect
as first argument - Result of function call is ignored
Arguments
hook
(Watcher): A function that receives Effect and will be called during every domain.createEffect call
Returns
Subscription: Unsubscribe function.
#
ExampleonCreateStore(hook)
#
#
Formulae- Function passed to
onCreateStore
called every time, as new store created indomain
- Function called with
$store
as first argument - Result of function call is ignored
Arguments
hook
(Watcher): A function that receives Store and will be called during every domain.createStore call
Returns
Subscription: Unsubscribe function.
#
ExampleonCreateDomain(hook)
#
#
Formulae- Function passed to
onCreateDomain
called every time, as sub domain created indomain
- Function called with
domain
as first argument - Result of function call is ignored
Arguments
hook
(Watcher): A function that receives Domain and will be called during every domain.createDomain call
Returns
Subscription: Unsubscribe function.