How to use the effector.createStoreObject 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 / recipes / media-queries / screenQueries.js View on Github external
//@flow

import {createStoreObject} from 'effector'
import {mediaMatcher} from './mediaMatcher'

/* declaring queries and merge them into single store*/

export const screenQueries = createStoreObject({
  small: mediaMatcher('(max-width: 768px)'),
  medium: mediaMatcher('(min-width: 769px) and (max-width: 1024px)'),
  large: mediaMatcher('(min-width: 1025px)'),
  portrait: mediaMatcher('(orientation: portrait)'),
})
github zerobias / effector / website / editor / src / editor / init.js View on Github external
options: {className: 'CodeMirror-lint-mark-error'},
    })
  }
})

changeSources.map(compress).watch(code => {
  localStorage.setItem('code-compressed', code)
})

forward({
  from: changeSources,
  to: sourceCode,
})

{
  const initStore = createStoreObject({
    sourceCode,
    versionLoader,
    typechecker,
  })
  initStore.watch(data => {
    console.log('init store update', data)
    evalEffect(data.sourceCode)
  })
}

changeSources(retrieveCode())
selectVersion(retrieveVersion())
github howtocards / frontend / src / pages / create / model.js View on Github external
import { history } from "@lib/routing"
import { cardsApi, type Card } from "@api/cards"

export const titleChanged = createEvent>()
export const contentChanged = createEvent<*>()
export const formSubmitted = createEvent<*>()
export const pageUnmounted = createEvent()

const cardCreate = createEffect()
export const cardCreateFetching: Fetching = createFetching(cardCreate)

export const $title = createStore("")
export const $content = createStore<{}>(
  Plain.deserialize("Start typing here...").toJS(),
)
const $form = createStoreObject({
  title: $title,
  content: $content,
})

const trimEvent = (event) => event.currentTarget.value

$title.on(titleChanged.map(trimEvent), (_, title) => title)
$content.on(contentChanged, (_, content) => content)
$form.reset(pageUnmounted)

formSubmitted.watch(() => {
  cardCreate($form.getState())
})

cardCreate.use(cardsApi.create)
github goodmind / treact / packages / treact / src / app / store / reducers.ts View on Github external
authKey: authKeyReducer,
  auth: authReducer,
  currentUser: currentUserReducer,
  users,
  peers,
  selected,
  histories,
  avatars,

  media,
  photos,
  photoSizes,
  photoCachedSizes,
})

export const rootStore = createStoreObject({
  messages,
  dialogs,
  documents,
  chats,
  theme,
  loadings,
  settings,
  files,
})

export default rootReducer
github today- / effector-react-inject / src / index.tsx View on Github external
export function inject(
    stores: {[key in K]: Store},
): any {
    const merged = createStoreObject(stores);
    const Consumer = createStoreConsumer(merged);

    return (
        Cmp: React.ComponentType,
    ) => (props: Props & {[key in K]: typeof stores[key]}) => (
        
            {state => }
        
    );
}
github howtocards / frontend / src / pages / join / registration / model.js View on Github external
registerProcessing,
)

export const $email = createStore("")
export const $emailError: Store = $email.map(emailValidator)
export const $isEmailCorrect = $emailError.map(
  (value) => value === null,
)

export const $password = createStore("")
export const $passwordError: Store = $password.map(passwordValidator)
export const $isPasswordCorrect = $passwordError.map(
  (value) => value === null,
)

export const $form = createStoreObject({
  email: $email,
  password: $password,
})

const $isFormValid = combine(
  $isPasswordCorrect,
  $isEmailCorrect,
  (isPasswordCorrect, isEmailCorrect) => isPasswordCorrect && isEmailCorrect,
)

export const $isFormDisabled = registerFetching.isLoading
export const $isSubmitEnabled: Store = combine(
  $isFormValid,
  registerFetching.isLoading,
  (isFormValid, isregisterFetching) => isFormValid && !isregisterFetching,
)
github DTupalov / react-material-ui-datatable / src / model / createModel.js View on Github external
$data,
    $columns,
    $sort,
    $searchValue,
    $filterValues
  );
  const { $filterLists } = createFilterLists($data, $columns);
  const { $displayData } = createDisplayData($computedData, $page, $perPage);
  const {
    $selectedData,
    toggleSelectRow,
    toggleSelectAll,
    handleSelect,
  } = createSelectedData(initialSelectedData, $computedData, handleDelete);

  const $store = createStoreObject({
    data: $data,
    columns: $columns,
    sort: $sort,
    filterValues: $filterValues,
    searchValue: $searchValue,
    showSearchBar: $showSearchBar,
    selectedData: $selectedData,
    page: $page,
    perPage: $perPage,
    computedData: $computedData,
    filterLists: $filterLists,
    displayData: $displayData,
  });

  const actions = {
    toggleSelectRow,
github zerobias / effector / src / vue / mixin.js View on Github external
[key: string]: any
    } = this
    const key = 'state'
    let shape = vm.$options.effector
    if (typeof shape === 'function') {
      shape = shape.call(vm)
    }
    if (shape) {
      if (is.store(shape) /*:: && isStore(shape) */) {
        //$off
        Vue.util.defineReactive(vm, key, shape.getState())
        vm._subscription = shape.subscribe(value => {
          vm[key] = value
        })
      } else if (typeof shape === 'object' && shape !== null /*:: && !isStore(shape) */) {
        const store = createStoreObject(shape)
        for (const key in shape) {
          //$off
          Vue.util.defineReactive(vm, key, store.defaultState[key])
        }
        vm._subscription = store.subscribe(value => {
          for (const key in value) {
            vm[key] = value[key]
          }
        })
      } else {
        throw Error('property should be Store')
      }
    }
  },
  beforeDestroy() {
github howtocards / frontend / src / pages / join / login / model.js View on Github external
export const $email = createStore("")
export const $emailError = $email.map(emailValidator)
export const $isEmailCorrect = $emailError.map(
  (value) => value === null,
)

export const $password = createStore("")
export const $passwordError = $password.map((value) => {
  if (value && value.length > 1) return null
  return "Please, enter password"
})
export const $isPasswordCorrect = $passwordError.map(
  (value) => value === null,
)

export const $form = createStoreObject({
  email: $email,
  password: $password,
})

const $isFormValid = combine(
  $isPasswordCorrect,
  $isEmailCorrect,
  (isPasswordCorrect, isEmailCorrect) => isPasswordCorrect && isEmailCorrect,
)

export const $isFormDisabled = loginFetching.isLoading
export const $isSubmitEnabled: Store = combine(
  $isFormValid,
  loginFetching.isLoading,
  (isFormValid, isLoginFetching) => isFormValid && !isLoginFetching,
)
github goodmind / treact / packages / treact / src / app / store / modules / settings / shape.ts View on Github external
document: boolean,
    video: boolean,
  },
}

export const autoMediaDownload = createStore({
  sticker: true,
  photo: true,
  voice: true,
  round: true,
  gif: true,
  document: false,
  video: false,
})

export const settings: Store = createStoreObject({
  autoMediaDownload,
})