effector-vue
Advanced tools
Changelog
effector-react 20.7.3, effector-vue 20.4.2
effector-react/compat
and effector-vue/compat
compatibility with IE11Changelog
effector-vue 20.4.0
import {createStore} from 'effector'
import {createComponent} from 'effector-vue'
const counter = createStore(0)
const component = createComponent(
{
template: '<div>{{ counter }}</div>',
watch: {
counter() {
/* side-effects here */
},
},
},
{counter},
)
Changelog
effector-react 20.6.2, effector-vue 20.3.3
Cdn with umd build of effector-react Cdn with umd build of effector-vue
Changelog
effector 20.3.2
split
method (PR)import React from 'react'
import ReactDOM from 'react-dom'
import {createStore, createEvent, createEffect, sample} from 'effector'
import {useList} from 'effector-react'
const updateItem = createEvent()
const resetItems = createEvent()
const processClicked = createEvent()
const processItemsFx = createEffect({
async handler(items) {
for (let {id} of items) {
//event call inside effect
//should be applied to items$
//only after processItemsFx itself
updateItem({id, status: 'PROCESS'})
await new Promise(r => setTimeout(r, 3000))
updateItem({id, status: 'DONE'})
}
},
})
const $items = createStore([
{id: 0, status: 'NEW'},
{id: 1, status: 'NEW'},
])
.on(updateItem, (items, {id, status}) =>
items.map(item => (item.id === id ? {...item, status} : item)),
)
.on(processItemsFx, items => items.map(({id}) => ({id, status: 'WAIT'})))
.reset(resetItems)
sample({
source: $items,
clock: processClicked,
target: processItemsFx,
})
const App = () => (
<section>
<header>
<h1>Jobs list</h1>
</header>
<button onClick={processClicked}>run tasks</button>
<button onClick={resetItems}>reset</button>
<ol>
{useList($items, ({status}) => (
<li>{status}</li>
))}
</ol>
</section>
)
ReactDOM.render(<App />, document.getElementById('root'))
Changelog
effector 20.3.1
clearNode
been called on store belonged to certain domain led to the removal of the entire domainChangelog
effector-vue 20.3.0
createComponent
HOC for TypeScript usage. This HOC provides type-safe properties in vue components.// component.vue
import {value createStore, value createApi} from 'effector'
import {value createComponent} from 'effector-vue'
const $counter = createStore(0)
const {update} = createApi($counter, {
update: (_, value: number) => value,
})
export default createComponent(
{
name: 'Counter',
methods: {
update,
handleClick() {
const value = this.$counter + 1 // this.$counter <- number ( typescript tips )
this.update(value)
},
},
},
{$counter},
)
Changelog
effector-vue 20.2.1
const counter = createStore(0)
new Vue({
effector: {
counter, // would create `counter` in template
},
})
Changelog
effector-vue 20.2.0
const counter = createStore(0)
new Vue({
effector: {
counter, // would create `counter` in template
},
})
Changelog
effector 20.1.2
event.filter({fn})
got a predicate function as a callback PRimport {value createEvent} from 'effector'
const event = createEvent<string | number>()
const isString = (value: any): value is string => typeof value === 'string'
const isNumber = (value: any): value is number => typeof value === 'number'
const str = event.filter({fn: isString}) // Event<string>
const num = event.filter({fn: isNumber}) // Event<number>
str.watch(value => value.slice()) // OK now
num.watch(value => value.toFixed(2)) // OK now
is
methods PRimport {value is} from 'effector'
//result has type Event<any> | void
function getEvent(obj: unknown) {
if (is.event(obj)) return obj
if (is.store(obj)) return obj.updates
}