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 creators
createEvent(name?)
Arguments
name
? (string): event name
Returns
Event: New event
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
Aliases
event(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 hooks
onCreateEvent(hook)
Arguments
hook
(Watcher): A function that receives Event and will be called during every domain.createEvent call
Returns
Subscription: Unsubscribe function.
Example
import {createDomain} from 'effector'
const domain = createDomain()
domain.onCreateEvent(event => {
console.log('new event created')
})
const a = domain.createEvent()
// => new event created
const b = domain.createEvent()
// => new event created
onCreateEffect(hook)
Arguments
hook
(Watcher): A function that receives Effect and will be called during every domain.createEffect call
Returns
Subscription: Unsubscribe function.
Example
import {createDomain} from 'effector'
const domain = createDomain()
domain.onCreateEffect(effect => {
console.log('new effect created')
})
const a = domain.createEffect()
// => new effect created
const b = domain.createEffect()
// => new effect created
onCreateStore(hook)
Arguments
hook
(Watcher): A function that receives Store and will be called during every domain.createStore call
Returns
Subscription: Unsubscribe function.
Example
import {createDomain} from 'effector'
const domain = createDomain()
domain.onCreateStore(store => {
console.log('new store created')
})
const a = domain.createStore(null)
// => new store created
const b = domain.createEffect(null)
// => new store created
onCreateDomain(hook)
Arguments
hook
(Watcher): A function that receives Domain and will be called during every domain.createDomain call
Returns
Subscription: Unsubscribe function.
Example
import {createDomain} from 'effector'
const domain = createDomain()
domain.onCreateDomain(domain => {
console.log('new domain created')
})
const a = domain.createDomain()
// => new domain created
const b = domain.createDomain()
// => new domain created