Skip to content

v6.0.0

Compare
Choose a tag to compare
@greena13 greena13 released this 12 May 21:08
· 40 commits to master since this release

Breaking changes

The reducesOn option now uses the action names as keys:

Before:

import { actions: userActions } from '../users.js';

const { actionCreators: { updateItem: updatePost } } = resources(
    {
        // ...
        reducesOn: {
          action: userActions.destroy,
          reducer: function() { // ...  }
       }
    },
    ['update']
);

After:

import { actions: userActions } from '../users.js';

const { actionCreators: { updateItem: updatePost } } = resources(
    {
        // ...
        reducesOn: {
          [userActions.destroy]:  function() { // ... }
       }
    },
    ['update']
);

Bugfixes (potentially breaking changes)

  • Using any of the list operations in the action creators (e.g. push, unshift, invalidate) with keys that don't match collections that exist in the Redux store, no longer create new empty collections. Instead, those collections are quietly ignored.
  • 204 No Content responses no longer clear an item or collection in the store - the old value is retained.

New features

  • The merge action creator option now accepts the new item as its second argument (previously it only had access to the items that were already in the collection) so the following is now possible:
const sortListItemsByImportance = (items, newItem) => {
  return itemsSortedByPriority([...items, newItem]).map(({ values: { id }}) => id);
}      

createTodoItem(
    { title: 'Pick up milk'}, 
    { merge: [['important'], sortListItemsByImportance ]}
);

Warning: The merge option is now considered deprecated and likely to be removed in future versions. You're better to use the reducesOn option when defining the resource, rather than passing function references on your action objects (which are not serialisable or lend themselves to being logged).

  • The updateItem action creator now accepts a sort option that allows sorting collections the item appears within, when the values that determine its order, are updated.

Warning: The sort option is also a candidate for deprecation. You're better to use the reducesOn option when defining the resource, rather than passing function references on your action objects (which are not serialisable or lend themselves to being logged).

  • Allow specifying a non-default HTTP request method for actions using the new method option
const { actionCreators: { fetchList: fetchUsers } } = resources(
    {
        // ...
    },
    {
        fetchList:  {
            method: 'POST'
        }
    }
);
  • Similarly, you can specify a custom action name using the actionName option (only really recommended for custom actions; not default RESTful ones):
const { actionCreators: { fetchList: fetchUsers } } = resources(
    {
        // ...
    },
    {
        fetchList:  {
            actionName: 'GET_USERS_COLLECTION'
        }
    }
);
  • Expose isStatus and isFinished helper methods for evaluating the status of an item or collection

  • Allow using the name of an action for the reducer option when defining an action, for instances where you want to re-use the same reducer for multiple actions. For example:

const { actionCreators: { updateItem: updatePost, publishItem: publishPost } } = resources(
    {
        // ...
    },
    {
        update: true,
        publish:  {
            // ....
            reducer: 'update'
        }
    }
);
  • Provide helper functions to the reducesOn, beforeReducers and afterReducers (see the full list) to make working with the data schema easier.

  • Allow reducesOn to use the name of another action on the same resource as a key. For example:

const { actionCreators: { updateItem: updatePost } } = resources(
    {
        // ...
        reducesOn: {
          update: function() { // extra stuff }
       }
    },
    {
        update: true,       
    }
);
  • Export a getNewOrExistingItem helper for retrieving an item from the store, and falling back to returning a new item if it's unavailable.

  • Allow passing an array of values to deselectItem, selectAnotherItem and selectItem to bulk manage selected items

  • Allow customising how item and collection params are serialised into a query or search string, using the queryStringOptions option.

Bugfixes (Non-breaking)

  • Fix error in de-duping of requests when no request is actually made
  • Fix getList and getOrFetchList not honouring the urlOnlyParams options when it's set globally
  • Fix HTTP status code not being correctly set for create and update response

Typescript improvements

  • Document actionCreator option for defining custom action creator functions for actions
  • Document reducer option for defining custom reducer functions for actions
  • Mark errorOcurredAt as an optional property