Giter VIP home page Giter VIP logo

dyad-fsa-fetch's Introduction

Dyad FSA Fetch Middleware

Installation

npm install dyad-fsa-fetch

Usage

require('isomorphic-fetch')
const Dyad = require('dyad')
const {middleware: dyadFsaFetch} = require('./dyad-fsa-fetch')
const {middleware: dyadFsaPromise} = require('dyad-fsa-promise')

const store = Dyad.getInstance()

store.use(dyadFsaFetch)
store.use(dyadFsaPromise)

store.bind({
  ACTION_TYPE: (_, __, action) => console.log(action.payload.value[0].guid)
})

// `dyad-fsa-fetch` will look for an `action.meta.fetch` property, intercept
// matching actions, call `fetch()` with `action.payload.url` plus any other
// optional properties, then dispatch a new action with the `fetch()` promise
// as a new `payload`.
store.dispatch({
  type: 'ACTION_TYPE',
  meta: {
    // `action.meta.fetch` determines which method will be used to decode the
    // response body and store the result as `action.payload.value`. You can
    // use any decoder method name your Fetch API supports (for example:
    // 'arrayBuffer', 'blob', 'formData', 'json', 'text') or 'raw' to forgo
    // decoding and leave `action.payload.value` undefined.
    fetch: 'json'
  },
  payload: {
    // Required property `url` and other optional properties will be used to
    // call `fetch()` so you can specify request initializer options like
    // `method: 'PUT'`, `headers: {'content-type': 'application/json'}`,
    // `body: '{"a": 1, "b": true, "c": "u"}'`, and so on.
    url: 'https://next.json-generator.com/api/json/get/4ylLYeUkB'
  }
})

// Logs '4d87721e-e7ba-418a-ba54-e666e645489e'

dyad-fsa-fetch's People

Contributors

mikol avatar

Watchers

 avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.