Skip to content

Releases: greena13/redux-and-the-rest

v6.1.3

12 Jul 13:01
Compare
Choose a tag to compare

Bugfixes

  • 🐛 Correct forceFetch type to include functions

v6.1.0

20 Oct 18:52
Compare
Choose a tag to compare

Breaking changes

  • isFinishedDestroying() has been renamed to itNotAvailableLocally() and fixed to return true for empty items retrieved using getItem(). isFinishedDestroying() never worked as described, and could not be patched to do so (once an item has been deleted from the store, it's indistinguishable from it never having been downloaded in the first place).

New features

  • deselectItem, deselectItems, selectAnotherItem, selectMoreItems, selectItem, selectItems and clearSelectedItems functions were added to the helpers available for beforeReducer, reducer, afterReducer and reducesOn resource options. See the helper object
  • Allow specifying a custom generateId() function. See the global configuration options

Bugfixes

  • Editing an item that has been retrieved from a remote source no longer clears the status attributes, causing isNew() to incorrectly report the item or list as new (thanks @sven95rd) #17

v6.0.0

12 May 21:08
Compare
Choose a tag to compare

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

v5.1.0

09 Oct 06:42
Compare
Choose a tag to compare

New features

List operations now accepts a wildcard allowing you to perform operations on all lists not explicitly referenced by its key.

List operations now allows specifying a custom merger, allowing you to define a custom function for merging in new items into the order of existing lists.

Bugfixes

  • Fix dispatchers not working with getOrFetch, getOrInitializeNewItem, saveItem
  • Fix forceFetch option no longer working with getOrFetchItem and getOrFetchList

v4.2.1

09 Oct 06:34
Compare
Choose a tag to compare

Bugfixes and potentially breaking changes

Fixes handling empty JSON responses.

v5.0.0

22 Sep 17:11
Compare
Choose a tag to compare

Breaking changes

  • isFinishedFetching(), isSyncingWithRemote(), isSyncedWithRemote(), isSyncedSuccessfully(), isInErrorState() have been removed in favour of a more consistently named helpers. See Data lifecyles for more information.

Bugfixes (possibly breaking changes)

  • Changed getOrFetch() to dispatch its first action asynchronously. This addresses React warnings when multiple mounted components in the same render cycle called getOrFetch(), triggering an update to the state of a parent component.

  • getOrFetchList() now returns lists with a status of FETCHING immediately (rather than one with an undefined status)

  • Fixed empty JSON responses causing a client-side parsing error.

New features

v4.2.0

22 Sep 16:58
Compare
Choose a tag to compare

New features

Default values for action creators can now be set using the global configure() function:

  • keyBy
  • beforeReducers
  • afterReducers
  • errorAttributes
  • transforms
  • urlOnlyParams
  • contentType

Bug fixes

  • Resolve issues with processing variable arguments for action creators.
  • Fixed the listOperations of localOnly resources being ignored

v4.1.0

18 Aug 17:13
Compare
Choose a tag to compare

New features (potentially breaking changes)

Singular resources can now specify params to send to the remote API when performing asynchronous actions, as their first (optional) parameter.

So now if an action creator resulting from a singular resource (as opposed to a resources) definition is called with 1 argument, it is interpreted as the values for the action creator. If it's called with two arguments, they're interpreted as params and values respectively. If 3 are provided, they're interpreted as params, values and action creator options (in that order).

For action creators that do not accept values (such as destroyItem or fetchItems), one argument is interpreted as params, two are processed as params and action creator options, respectively.

Warning: This may be a breaking change if you were using the action creator options for a singular resource action creator. You will need to now explicitly define a params value as the first argument. To replicate the previous behaviour, use the UNSPECIFIED_KEY constant.

Before:

fetchItems({ force: true });

After:

import { UNSPECIFIED_KEY } from 'redux-and-the-rest';

fetchItems(UNSPECIFIED_KEY, { force: true });

v4.0.4

04 Aug 17:14
Compare
Choose a tag to compare

New features

  • New global configuration options, for configuring Accept and Content-Type headers for requests, acceptType, contentType and errorContentType.

Bugfixes

  • Fix isNew helper not returning true after a resource has failed to create
  • Fix the name of the editNewOrExistingItem action
  • Fix an item's temporary key being added multiple times to a collection's positions if it fails to create the first time

v4.0.3

04 Aug 17:10
Compare
Choose a tag to compare

Breaking changes

  • (Breaking if you used this feature in v4.0.2): Removed ability to edit new items using the editItem action creator - this ended up breaking a number of assumptions.

New features

  • Added a new editNewOrExistingItem action creator (See here)

Bugfixes

  • Fixed forceFetch TypeScript definition
  • Fixed collection operation TypeScript definitions