Skip to content
This repository has been archived by the owner on Aug 26, 2019. It is now read-only.
/ teardux Public archive

Redux, using rematch, hopefully without the tears.

License

Notifications You must be signed in to change notification settings

dcousens/teardux

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

13 Commits
 
 
 
 
 
 
 
 

Repository files navigation

DEPRECATED: Do not use

teardux

Redux, using rematch, hopefully without the tears.

WARNING: Work in progress, may not use rematch in near future.

Example

import teardux from 'teardux'

type TodoItem = {
  title: string
  text: string
  complete: bool
}

const DEFAULT_TODO_ITEM: TodoItem = {
  title: '',
  text: '',
  complete: false
}

// WARNING: returns a rematch model, may change in near future
const todoModel = teardux<TodoItem>(DEFAULT_TODO_ITEM, {
  get: (id: string, rootState, callback) => {
    if (Math.random() > 0.1) return callback(new Error('ETIMEOUT'))

    setTimeout(() => {
      callback(null, {
        title: 'A title',
        text: 'A task to do',
        complete: true
      })
    }, 100)
  }
})

// ...
import { init } from '@rematch/core'

// rematch initialization
const rematch = init({
  todo: todoModel
})

// ...

function mapStateToProps (state) {
  const { error, loading, success, item } = state.todo
  const { title, complete } = item

  return {
    error,
    loading,
    success,
    item: {
      title,
      complete
    }
  }
}

function mapDispatchToProps (dispatch) {
  fetchItem: async (itemId) {
    await dispatch.todo.get(itemId)
  }
}

LICENSE MIT

About

Redux, using rematch, hopefully without the tears.

Topics

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published