redux-fetch
Declarative data-fetching for redux
Last updated 5 years ago by ashaffer88 .
MIT · Repository · Bugs · Original npm · Tarball · package.json
$ cnpm install redux-fetch 
SYNC missed versions from official npm registry.

redux-fetch

Declarative data fetching for redux

Warning

I am developing this still as we speak, I would not expect anything in here to work at the moment, or the documentation to be up to date. I'll remove this if/when it's more stable. It's just up here for my own use and so that people can get the gist of the concept and play around with it if they want.

Usage

Add redux-fetch to your redux middleware stack (preferably at the beginning). Then, instead of imperatively calling fetch in your action creators, you can produce descriptions of the fetch you want to perform, and the middleware will execute it for you.

function createUser (user) {
  return {
    type: 'FETCH',
    payload: {
      method: 'POST',
      url: '/user',
      body: user
    },
    meta: {
      then: logUserIn
    }
  }
}

function logUserIn () {
  return {
    type: 'USER_DID_LOGIN'
  }
}

Coming soon

Less-verbose ways of doing this. Going to try to create some creators for these things, so that the API can be just like fetch. Something like:

var fetch = require('declarative-fetch')

function createUser (user) {
  return fetch('/user/', {
    method: 'post',
    body: user
  })
  .then(logUserIn)
}

Current Tags

  • 0.1.2                                ...           latest (5 years ago)

3 Versions

  • 0.1.2                                ...           5 years ago
  • 0.1.1                                ...           5 years ago
  • 0.1.0                                ...           5 years ago
Maintainers (1)
Downloads
Today 0
This Week 0
This Month 0
Last Day 0
Last Week 1
Last Month 2
Dependencies (2)
Dev Dependencies (0)
None
Dependents (2)

Copyright 2014 - 2017 © taobao.org |