kyrios

0.0.2 • Public • Published

Experimental state management library. Alpha state.

  • Basic Model
// @flow
import makeModel from 'core/makeModel'
import api from './api'
import { type $Models } from '../types'

const user = makeModel<$Models, 'user'>({
  state: null,
  reducers: () => ({
    set: payload => payload,
    unset: () => null,
  }),
  effects: (self, store) => ({
    async signIn(payload): Promise<void> {
      try {
        const data = await api.signIn(payload)
        self.set(data)
      } catch (err) {
        self.unset()
        store.toaster.pushMsg('Failed SignIn, please try again')
      }
    },
  }),
  // Queries are equivalent to redux selectors, but without
  // the need to manually pass them the state at runtime
  queries: state => ({
    state: () => state,
  }),
})

export default user

Dependencies (2)

Dev Dependencies (25)

Package Sidebar

Install

npm i kyrios

Weekly Downloads

2

Version

0.0.2

License

MIT

Unpacked Size

290 kB

Total Files

102

Last publish

Collaborators

  • zaggen