0.2.1 • Published 8 years ago

declarative-promise v0.2.1

Weekly downloads
5
License
MIT
Repository
github
Last release
8 years ago

declarative-promise

Produce declarative specifications of your promise chains. Designed to be used in conjunction with redux-effects

Installation

npm install declarative-promise

Usage

DeclarativePromise's export a step function in place of the then of a standard Promise. step accepts two functions, a success handler and an error handler and it returns a new DeclarativePromise. Where it differs from a standard promise is that it doesn't actually execute any of the functions in your chain on its own. It doesn't do anything at all on it's own, other than construct a tree of pure computations to execute.

In order to actually execute your tree, you need a separate library to do that, such as redux-effects.

From an async action creator:

import DeclarativePromise from 'declarative-promise'

function getUrl (url) {
  return new DeclarativePromise({
    type: 'EFFECT',
    payload: {
      type: 'FETCH',
      url
    }
  })
}

From application-level code:

import getUrl from 'get-url'
import {createAction} from 'redux-actions'

const gotGoogle = createAction('GOT_GOOGLE')

function fetchGoogle () {
  return getUrl('http://www.google.com')
    .step(gotGoogle)
}
0.2.1

8 years ago

0.1.12

9 years ago

0.1.11

9 years ago

0.1.10

9 years ago

0.1.9

9 years ago

0.1.8

9 years ago

0.1.7

9 years ago

0.1.6

9 years ago

0.1.5

9 years ago

0.1.4

9 years ago

0.1.3

9 years ago

0.1.2

9 years ago

0.1.1

9 years ago

0.1.0

9 years ago