Releases: greena13/redux-and-the-rest
v6.1.3
v6.1.0
Breaking changes
isFinishedDestroying()
has been renamed toitNotAvailableLocally()
and fixed to returntrue
for 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
,selectItems
andclearSelectedItems
functions were added to the helpers available forbeforeReducer
,reducer
,afterReducer
andreducesOn
resource 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
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 asort
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
andisFinished
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
andafterReducers
(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
andselectItem
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
andgetOrFetchList
not honouring theurlOnlyParams
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
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
andgetOrFetchList
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 ofFETCHING
immediately (rather than one with an undefined status) -
Fixed empty JSON responses causing a client-side parsing error.
New features
- In addition to action creators,
resources
andresource
now 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 alocalOnly
resource, 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
localOnly
actions - 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:
keyBy
beforeReducers
afterReducers
errorAttributes
transforms
urlOnlyParams
contentType
Bug fixes
- Resolve issues with processing variable arguments for action creators.
- Fixed the
listOperations
oflocalOnly
resources 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
Accept
andContent-Type
headers for requests,acceptType
,contentType
anderrorContentType
.
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
Breaking changes
- (Breaking if you used this feature in
v4.0.2
): Removed ability to edit new items using theeditItem
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