import { a } from './state'
const value = useStore(a)
import { createEffect } from 'effector'
const loadPatient = createEffect({
handler: (patientId: string) => http.get(`/patients/${patientId}`)
})
loadPatient.watch(() => console.log("Start loading"))
loadPatient.done.watch(() => console.log("Successfully loaded"))
loadPatient.fail.watch(() => console.log("Error"))
loadPatient.finally.watch(() => console.log("Operation completed"))
// or use as regular function
const patient = await loadPatient("123")
import { createStore } from 'effector'
import { loadPatient, Patient } from './patients'
export const patientIsLoading = createStore(false)
.on(loadPatient, () => true)
.reset(loadPatient.finally)
patientIsLoading
.watch(value => console.log('Store value', value))
import { createStore } from 'effector'
import { loadPatient, Patient } from './patients'
// todo: complicated private store
// expose more primitive store with only data that is allowed to expose
import { createStore } from 'effector'
import { loadPatient, Patient } from './patients'
// todo: complicated private store
// expose more primitive store with only data that is allowed to expose
import { merge } from 'effector'
import { participantLeft, participantJoined } from './participants'
const participanListChanged = merge([participantLeft, participantJoined])
participanListChanged.watch(() => console.log('participant list changed'))
import { split } from 'effector'
import { participantJoined } from './participants'
const byRole = split(participantJoined, {
patient: ({role}) => role === 'patient',
provider: ({role}) => role === 'provider'
})
byRole.patient.wathc(() => console.log('patient joined!'));
import { split, createStore, createEffect, guard } from 'effector'
import { participantJoined } from './participants'
const byRole = split(participantJoined, {
patient: ({role}) => role === 'patient',
provider: ({role}) => role === 'provider'
})
const counter = createStore(0)
.on(byRole.patient, (count) => count + 1)
const horray = createEffect()
.use(() => {console.log("Patient joined 3 times!")})
guard({
source: counter,
filter: count => count % 3 === 0,
target: horray,
})