Repository navigation
Releases: greena13/redux-and-the-rest
Release list
v6.1.3
v6.1.0
Breaking changes
isFinishedDestroying()has been renamed toitNotAvailableLocally()and fixed to returntruefor empty items retrieved usinggetItem().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,selectItemsandclearSelectedItemsfunctions were added to the helpers available forbeforeReducer,reducer,afterReducerandreducesOnresource options. See the helper object- Allow specifying a custom
generateId()function. See the global configuration options
Bugfixes
v6.0.0
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
mergeaction 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
updateItemaction creator now accepts asortoption 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
methodoption
const { actionCreators: { fetchList: fetchUsers } } = resources(
{
// ...
},
{
fetchList: {
method: 'POST'
}
}
);- Similarly, you can specify a custom action name using the
actionNameoption (only really recommended for custom actions; not default RESTful ones):
const { actionCreators: { fetchList: fetchUsers } } = resources(
{
// ...
},
{
fetchList: {
actionName: 'GET_USERS_COLLECTION'
}
}
);-
Expose
isStatusandisFinishedhelper methods for evaluating the status of an item or collection -
Allow using the name of an action for the
reduceroption 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,beforeReducersandafterReducers(see the full list) to make working with the data schema easier. -
Allow
reducesOnto 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
getNewOrExistingItemhelper 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,selectAnotherItemandselectItemto bulk manage selected items -
Allow customising how item and collection params are serialised into a query or search string, using the
queryStringOptionsoption.
Bugfixes (Non-breaking)
- Fix error in de-duping of requests when no request is actually made
- Fix
getListandgetOrFetchListnot honouring theurlOnlyParamsoptions when it's set globally - Fix HTTP status code not being correctly set for create and update response
Typescript improvements
- Document
actionCreatoroption for defining custom action creator functions for actions - Document
reduceroption for defining custom reducer functions for actions - Mark
errorOcurredAtas an optional property
v5.1.0
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
getOrFetchItemandgetOrFetchList
v4.2.1
v5.0.0
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 calledgetOrFetch(), triggering an update to the state of a parent component. -
getOrFetchList()now returns lists with a status ofFETCHINGimmediately (rather than one with an undefined status) -
Fixed empty JSON responses causing a client-side parsing error.
New features
- In addition to action creators,
resourcesandresourcenow export dispatchers - Added a new
saveItem()function for creating or updating a resource item based what state its currently in. - Added a
getOrInitializeItem()function for automatically instantiating new resources not in the store. getOrFetchItem()andgetOrFetchList()can now be used with alocalOnlyresource, to maintain a more consistent interface when interacting with local resources and remote ones- Fixed TypeScript argument types for the
buildInitialStatus()function for singular resources - Fix argument processing for defining
localOnlyactions - Added a new
isNewItemkey()function for evaluating a value matches the one being used as the key for the newest item. - Added a new
getHttpStatusCode()function for returning the HTTP status code of the last request performed on an item or list.
v4.2.0
New features
Default values for action creators can now be set using the global configure() function:
keyBybeforeReducersafterReducerserrorAttributestransformsurlOnlyParamscontentType
Bug fixes
- Resolve issues with processing variable arguments for action creators.
- Fixed the
listOperationsoflocalOnlyresources being ignored
v4.1.0
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
New features
- New global configuration options, for configuring
AcceptandContent-Typeheaders for requests,acceptType,contentTypeanderrorContentType.
Bugfixes
- Fix
isNewhelper not returning true after a resource has failed to create - Fix the name of the
editNewOrExistingItemaction - Fix an item's temporary key being added multiple times to a collection's
positionsif it fails to create the first time
v4.0.3
Breaking changes
- (Breaking if you used this feature in
v4.0.2): Removed ability to edit new items using theeditItemaction creator - this ended up breaking a number of assumptions.
New features
- Added a new
editNewOrExistingItemaction creator (See here)
Bugfixes
- Fixed
forceFetchTypeScript definition - Fixed collection operation TypeScript definitions