Repository
Current version released
4 years ago
Versions
- effector-vue@23.1.0Latest
- effector@23.2.3
- effector@23.2.2
- effector-react@23.2.1
- effector@23.2.1
- effector-react@23.2.0
- effector@23.2.0
- effector@23.1.0
- effector-react@23.1.0
- effector-react@23.0.1
- effector@23.0.0
- effector-react@23.0.0
- effector-vue@23.0.0
- effector-solid@0.23.0
- effector@22.8.8
- effector@22.8.7
- effector-react@22.5.4
- effector-react@22.5.3
- effector@22.8.6
- effector-react@22.5.2
- effector@22.8.5
- effector@22.8.4
- effector@22.8.3
- effector@22.8.2
- effector@22.8.1
- effector-react@22.5.1
- effector@22.7.0
- effector@22.6.2
- effector@22.6.1
- effector@22.6.0
- effector@22.5.2
- effector@22.5.1
- effector-react@22.5.0
- effector@22.5.0
- effector-solid@0.22.7
- effector-react@22.4.0
- effector@22.4.1
- effector@22.4.0
- effector-react@22.3.4
- effector-react@22.3.3
- effector-react@22.3.1
- effector-vue@22.2.0
- effector-react@22.3.0
- effector-solid@0.22.6
- effector-solid@0.22.5
- effector-react@22.2.0
- effector-solid@0.22.4
- effector-vue@22.1.2
- effector-solid@0.22.3
- forest@0.21.2
- effector-react@22.1.6
- effector-solid@0.22.2
- effector-react@22.1.5
- effector-react@22.1.1
- effector-react@22.1.0
- effector@22.3.0
- forest@0.21.1
- forest@0.21.0
- effector@22.2.0
- effector@22.2.0-rc.1
- effector-vue@22.1.0
- effector-react@22.0.6
- effector@22.1.2
- effector@22.1.1
- effector@22.1.0
- effector@22.0.0
- effector-react@21.3.3
- effector@21.8.12
- effector@21.8.1
- effector@21.8.2
- effector@21.8.3
- effector@21.8.4
- effector-vue@21.1.1
- effector@21.8.5
- effector@21.8.6
- effector@21.8.7
- effector@21.8.8
- effector@21.8.9
- effector@21.8.10
- effector@21.8.11
- effector-react@21.3.1
- effector-react@21.3.0
- effector@21.8.0
- effector-react@21.2.0
- effector-react@21.1.0
- effector@21.7.0
- effector@21.6.0
- effector@21.5.0
- effector@21.4.0
- 21.3.0
- v0.18.2
- v0.18.1
- v0.18.0
- v0.18.0-rc.2
- v0.18.0-beta.11
- v0.18.0-beta.10
- v0.17.6
- v0.17.4
- v0.16.1-beta.12
- v0.14.0
- effector@21.2.0
- effector@21.1.0
- effector@21.0.3
- effector@21.0.0
- effector@20.17.2
- effector@20.17.1
- effector@20.17.0
- effector@20.16.1
- effector@20.16.0
- effector@20.15.8
- effector@20.15.1
- effector@20.15.0
- effector@20.14.0
- effector@20.13.7
- effector@20.13.6
- effector@20.13.5
- effector@20.13.4
- effector@20.13.3
- effector@20.13.2
- effector@20.13.1
- effector@20.13.0
- effector@20.12.2
- effector@20.12.1
- effector@20.12.0
- effector@20.11.5
- effector@20.11.3
- effector@20.11.2
- effector@20.11.1
- effector@20.11.0
- effector@20.10.2
- effector@20.10.1
- effector@20.10.0
- effector@20.9.0
- effector@20.8.2
- effector@20.8.1
- effector@20.8.0
- effector@20.7.1
- effector@20.7.0
- effector@20.6.2
- effector@20.6.1
- effector@20.6.0
- effector@20.5.0
- effector@20.4.4
- effector@20.4.3
- effector@20.4.1
- effector@20.4.0
- effector@20.3.2
- effector@20.3.1
- effector@20.3.0
- effector@20.2.0
- effector@20.1.2
- effector@20.1.1
- effector@20.1.0
- effector@20.0.0
- effector@19.1.0
- effector@19.0.0
- effector@0.18.10
- effector@0.18.9
- effector@0.18.8
- effector@0.18.7
- effector@0.18.6
- effector@0.18.5
- effector@0.18.5-beta.6
- effector@0.18.5-beta.5
- effector@0.18.5-beta.4
- effector@0.18.5-beta.3
- effector@0.18.5-beta.2
- effector@0.18.5-beta.1
- effector@0.18.4
- effector@0.18.3-beta.1
- effector@0.18.1
- effector@0.18.0
- @effector/forms@0.0.1
- @effector/babel-plugin@0.5.0
- @effector/babel-plugin@0.4.0
- @effector/babel-plugin@0.3.0
- @effector/babel-plugin@0.2.0
- @effector/babel-plugin-react@0.2.1
- @effector/babel-plugin-react@0.2.0
- effector-vue@21.0.3
- effector-vue@21.0.0
- effector-vue@20.5.0
- effector-vue@20.4.2
- effector-vue@20.4.1
- effector-vue@20.4.0
- effector-vue@20.3.3
- effector-vue@20.3.2
- effector-vue@20.3.0
- effector-vue@20.2.1
- effector-vue@20.2.0
☄️ Effector
Reactive state manager
Table of Contents
Installation
npm install --save effector effector-react
Or using yarn
yarn add effector effector-react
About
Effector provides events and reactive storages for node.js and browsers
Hello world with events and nodejs
const {createEvent} = require('effector')
const messageEvent = createEvent('message event (optional description)')
messageEvent.watch(text => console.log(`new message: ${text}`))
messageEvent('hello world')
// => new message: hello world
Storages and events
const {createStore, createEvent} = require('effector')
const turnOn = createEvent()
const turnOff = createEvent()
const status = createStore('offline')
.on(turnOn, () => 'online')
.on(turnOff, () => 'offline')
status.watch(newStatus => {
console.log(`status changed: ${newStatus}`)
})
turnOff()
turnOn()
turnOff()
turnOff() // Will not trigger watch function because nothing has changed
/*
result:
status changed: offline
status changed: online
status changed: offline
*/
Demo
Wiki
Usage
import {
createStore,
createEvent,
createEffect,
createStoreObject,
} from 'effector'
import {createStoreConsumer} from 'effector-react'
const changeText = createEvent('change todo text')
const clickSave = createEvent('click save')
const toggleComplete = createEvent('toggle complete')
const resetForm = createEvent('reset form')
const addTodo = createEvent('add todo')
const fetchSaveTodo = createEffect('save request')
const todos = createStore([]).on(fetchSaveTodo.done, (state, {params}) => [
...state,
params,
])
const text = createStore('').on(changeText, (_, newText) => newText)
const complete = createStore(false).on(toggleComplete, complete => !complete)
const form = createStoreObject({
text,
complete,
}).reset(resetForm)
const FormStore = createStoreConsumer(form)
const Form = () => (
<FormStore>
{form => (
<form onSubmit={resetForm}>
<input type="text" onChange={e => changeText(e.currentTarget.value)} />
<button onClick={resetForm}>reset</button>
</form>
)}
</FormStore>
)
Domain hooks
- onCreateEvent
- onCreateEffect
- onCreateStore
- onCreateDomain (to handle nested domains)
import {createDomain} from 'effector'
const mainPage = createDomain('main page')
mainPage.onCreateEvent(event => {
console.log('new event: ', event.getType())
})
mainPage.onCreateStore(store => {
console.log('new store: ', store.getState())
})
const mount = mainPage.event('mount')
// => new event: main page/mount
const pageStore = mainPage.store(0)
// => new store: 0
Typings
Effector supports both TypeScript and Flow type annotations out of the box.
API
import {
createEvent,
createEffect,
createDomain,
createStore,
createStoreObject,
} from 'effector'
See also Wiki
Core types
import type {Domain, Event, Effect, Store} from 'effector'
Contributors
Dmitry 💬 💻 📖 💡 🤔 🚇 ⚠️ |
andretshurotshka 💬 💻 📖 📦 ⚠️ |
Sergey Sova 📖 💡 |
Arutyunyan Artyom 📖 💡 |
---|