Skip to content

Releases: pburtchaell/redux-promise-middleware

Release 3.1.0

25 Jun 23:38
Compare
Choose a tag to compare

The rejected parameter for a promise is now an error object. This change is not breaking.

// before
Promise.reject('foo').catch(error => {
  console.log(error instanceof Error); // => false
});

// after
Promise.reject('foo').catch(error => {
  console.log(error instanceof Error); // => true
});

// error object keys remain the same as 3.0.x
Promise.reject('foo').catch(({ reason, action }) => {
  console.log(reason); // => 'foo'
});

Release 3.0.2

14 Jun 14:00
Compare
Choose a tag to compare

Removes

  • node_modules from npm

Version 3.0.1

05 Jun 14:57
Compare
Choose a tag to compare

Removes:

  • docs/ folder from npm
  • examples/ folder from npm

Version 2.4.0

17 May 16:55
Compare
Choose a tag to compare

This is the first release under the @Prev dist tag on npm

breaking

  • removes the feature of resolving custom actions in favour of resolving thunks for providing the same functionality.
  • returns original promise from dispatch instead of a custom action

notes
if your original promise rejects, you can optionally catch it yourself from the caller of the action creator -- also if your promises have extra functionality (such as try or finally), this will be available from the caller.

Version 3.0.0

31 Mar 12:59
Compare
Choose a tag to compare

This release introduces some major changes to the functionality of the middleware:

First, the middleware returns a promise instead of the action.

// before
const foo = () => ({
  type: 'FOO',
  payload: {
    promise: Promise.resolve('foo')
  }
});

foo().action.promise.then(value => {
  console.log(value); // => 'foo'
});

// after
const bar = () => ({
  type: 'BAR',
  payload: Promise.resolve('bar')
});

bar().then(({ value }) => {
  console.log(value); // => 'bar'
});

Second, a new promise is created so .then() and .catch() work as expected.

// before
const foo = () => ({
  type: 'FOO',
  payload: {
    promise: Promise.reject('foo')
  }
});

foo().action.promise.then(
  value => {
    console.log(value); // => 'foo'
  },
  reason => {
    // nothing happens
  }
);

// after
const bar = () => ({
  type: 'BAR',
  payload: Promise.reject('bar')
});

bar().then(
  ({ value }) => {
    // ...
  },
  ({ reason }) => {
    console.log(reason); // => 'bar'
  }
);

const baz = () => ({
  type: 'BAZ',
  payload: new Promise((resolve, reject) => {
    throw 'baz'
  })
});

bar().catch(({ reason }) => {
  console.log(reason) // => 'baz'
});

Third, promises can be explicitly or implicitly in the action object.

// before
const foo = () => ({
  type: 'FOO',
  payload: {
    promise: Promise.resolve()
  }
});

// after, with implicit promise as the value of the 'payload' property
const bar = () => ({
  type: 'BAR',
  payload: Promise.resolve()
});

Of course, if you prefer the explicit syntax, this still works. This syntax is also required for optimistic updates.

// after, but with explicit 'promise' property and 'data' property
const bar = () => ({
  type: 'BAZ',
  payload: {
    promise: Promise.resolve(),
    data: ...
  }
});

Fourth, thunks are no longer bound to the promise. If you are chaining actions with Redux Thunk, this is critical change.

// before, with Redux Thunk
const foo = () => ({
  type: 'FOO',
  payload: {
    promise: new Promise((resolve, reject) => {
      ...
    }).then(
      value => (action, dispatch) => {
        // handle fulfilled
        dispatch(someSuccessHandlerActionCreator());
      },
      reason => (action, dispatch) => {
        // handle rejected
        dispatch(someErrorHandlerActionCreator());
      }
    )
  }
});

// after, with Redux Thunk
const bar = () => {
  return (dispatch, getState) => {


    return dispatch({
      type: 'FOO',
      payload: Promise.resolve('foo')
    }).then(
      ({ value, action }) => {
        console.log(value); // => 'foo'
        console.log(action.type); // => 'FOO_FULFILLED'
        dispatch(someSuccessHandlerActionCreator());
      },
      ({ reason, action }) => {
        // handle rejected
        dispatch(someErrorHandlerActionCreator());
      }
    );
  };
};

Version 2.2.4

29 Nov 16:45
Compare
Choose a tag to compare

This release binds the first argument of any function given to Promise.resolve to a partial action object so one can access the original meta and an appropriate type within their thunk.

Version 2.2.3

29 Nov 16:39
Compare
Choose a tag to compare

Fixes a critical bug in version 2.2.2. 🔥 🚒

Please note that version 2.2.2 has also been deprecated on npm.

Version 2.2.2

26 Nov 18:21
Compare
Choose a tag to compare

With the previous release, dispatched actions are set through the entire stack of middleware.

const actionCreator = () => ({
  type: 'EXAMPLE_TYPE',
  payload: {
    promise: Promise.resolve({
      type: 'RESOLVED_ACTION' 
      payload: ...
    })
   }
});

However, this middleware does not check to see if the resolved or rejected parameter is a function. This release adds a check for thunk /function before resolving or rejecting as payload.

For example, now the following will also work:

const actionCreator = () => ({
  type: 'EXAMPLE_TYPE',
  payload: {
    promise: Promise.resolve((dispatch, getState) => {
      dispatch({ type: 'RESOLVED_ACTION', payload: '' })
      dispatch(someActionCreatorThatMaybeUpdatesTheRoute())
      doSomethingNaughtyAfterDispatchingEverything(getState())
    })
   }
});

This is not a breaking change.

Version 2.2.1

19 Nov 17:38
Compare
Choose a tag to compare

Instead of calling next() to dispatch rejected and fulfilled actions, the middleware now recalls dispatch() and dispatches entirely new actions. This is not a breaking change.

Version 2.2.0

08 Nov 20:52
Compare
Choose a tag to compare

Breaking Changes 🔥

  • In the case that the promise resolves null, the middleware will dispatch an empty object instead of dispatching null.