How to use the effector.createDomain function in effector

To help you get started, we’ve selected a few effector examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github zerobias / effector / src / forms / index.js View on Github external
loading: Store,
  handleSubmit: Event,
  reset: Event,
  handle: $ObjMap(V) => Event>,
  api: $ObjMap(V) => Event>,
|}

// TODO: split fields into stores
// export function createFormValue(name: string, defaultState: State) {
//   const value = createStore(defaultState)
//   const update = createEvent(`update ${name}`)
//   value.on(update, (_, p) => p)
//   return {value, update}
// }

const formDomain = createDomain('forms')

export function createFormApi<
  Form: {[key: string]: any, ...},
  External: {[key: string]: any, ...},
  Errors: {[key: string]: any, ...},
  Data,
  Error,
>({
  fields,
  external,
  submitEvent,
  submitEffect,
  validate,
  initialValues,
  domain = formDomain,
  resetOnSubmit = true,
github zerobias / effector / website / editor / src / settings / domain.js View on Github external
// @flow

import {combine, type Store, type Effect, createDomain} from 'effector'

const domain = createDomain('settings')

domain.onCreateStore(store => {
  const snapshot = localStorage.getItem(store.compositeName.fullName)
  if (snapshot != null) {
    const data = JSON.parse(snapshot)
    store.setState(data)
  }

  store.updates.watch(newState => {
    localStorage.setItem(store.compositeName.fullName, JSON.stringify(newState))
  })
  return store
})

export const flowToggle = domain.store(false)
export const flowToggleChange = domain.event>()
github zerobias / effector / src / babel / __tests__ / fixtures / create-domain.js View on Github external
//@flow
import {createDomain} from 'effector'

const domain = createDomain()
const foo = createDomain('bar')
github zerobias / effector / src / babel / __tests__ / fixtures / create-domain-effect.js View on Github external
//@flow
import {createDomain} from 'effector'

const domain = createDomain()

const a = domain.effect()
const f = () => domain.effect()
const b = domain.effect('hello')
const g = () => domain.effect('baz')
const aAlias = domain.createEffect()
const fAlias = () => domain.createEffect()
const bAlias = domain.createEffect('helloAlias')
const gAlias = () => domain.createEffect('bazAlias')
github zerobias / effector / src / babel / __tests__ / fixtures / create-domain-store.js View on Github external
//@flow
import {createDomain} from 'effector'

const domain = createDomain()

const a = domain.store('bar')
const b = domain.store('h', {option: 'test', ['na' + 'me']: 'LOL'})
const c = domain.store('h', {name: 'test'})
//$off
const d = domain.store('h', null)
//$off
const e = domain.store('h', 4234)
const f = domain.store('h', {})

const aAlias = domain.createStore('bar')
const bAlias = domain.createStore('h', {option: 'test', ['na' + 'me']: 'LOL'})
const cAlias = domain.createStore('h', {name: 'testAlias'})
//$off
const dAlias = domain.createStore('h', null)
//$off
github zerobias / effector / src / babel / __tests__ / fixtures / create-domain-event.js View on Github external
//@flow
import {createDomain} from 'effector'

const domain = createDomain()

const a = domain.event()
const f = () => domain.event()
const b = domain.event('asm')
const g = () => domain.event('tasm')
const aAlias = domain.createEvent()
const fAlias = () => domain.createEvent()
const bAlias = domain.createEvent('asmAlias')
const gAlias = () => domain.createEvent('tasmAlias')
github zerobias / effector / src / babel / __tests__ / fixtures / create-domain.js View on Github external
//@flow
import {createDomain} from 'effector'

const domain = createDomain()
const foo = createDomain('bar')
github zerobias / effector / src / babel / __tests__ / fixtures / create-domain-domain.js View on Github external
//@flow
import {createDomain} from 'effector'

const domain = createDomain()
const foo = domain.domain()
const bar = domain.domain('baz')

const fooAlias = domain.createDomain()
const barAlias = domain.createDomain('bazAlias')
github zerobias / effector / examples / react-ssr / src / app.tsx View on Github external
import React from 'react'
import fetch from 'cross-fetch'
import {sample, createDomain, forward, guard} from 'effector'
import {scopeBind} from 'effector/fork'
import {
  useStore,
  useList,
  useStoreMap,
  Provider,
  useEvent,
} from 'effector-react/ssr'
import users from './users.json'

export const app = createDomain()

export const startServer = app.createEvent()
export const startClient = app.createEvent()

const isServer = app
  .createStore(true)
  .on(startClient, () => false)
  .reset(startServer)

const selectUserEvent = app.createEvent()

const fetchUser = app.createEffect({
  async handler(bin: string) {
    return (await fetch('https://api.myjson.com/bins/' + bin)).json()
  },
})