The core methodology and functionality of resourcerer
has not changed in version 2.0, but many of the APIs have. Here is a list of the changes:
-
ModelMap#add
has been removed. Importregister
fromresourcerer
instead. -
There are no longer any
ResourceKeys
that are separate from the keys set on theModelMap
. They are one and the same:// previous ResourceKeys.add({ TODOS: "todos", }); ModelMap.add({ [ResourceKeys.TODOS]: TodosCollection }); // now register({ // `todos` is the resource key you will use in useResources Executor Functions todos: TodosCollection, });
Typescript will ensure that your resource keys are consistent when using useResources
. If you're not using Typescript, you'll have to manage this yourself.
Many other 2.0 changes stem from this change.
-
ExecutorFunctions only take a single argument, the
props
argument. Previously, the first argument was theResourceKeys
object. -
static cacheFields
in Models and Collections have been removed. Usestatic dependencies
instead. -
static modelIdAttribute
on a Collection, which changed the data attribute demarcating uniqueness in the Collection's models without having to create a new model, has been renamed to juststatic idAttribute
, the same as on the Model itself. -
In the Resource Configuration Object, the
options
property has been renamed topath
, since it is effectively only used to provide values to url path parameters. -
The utility methods
haveAllLoaded
,areAnyLoading
, andhaveAnyErrored
have been placed under a top-levelUtils
object and are now namedUtils.hasLoaded
,Utils.isLoading
, andUtils.hasErrored
, resepectively, to provide consistency with other loading state names. Their signatures have not changed. -
The refetch method returned from
useResources
no longer accepts a function as an argument. Pass an array of resource keys directly instead:// previously refetch(({todos}) => [todos]); // now refetch([todos]);
-
dependsOn is no longer an array of strings that checks existence of prop fields. To be more versatile, it is a boolean, and will fetch the resource whenever its conditions evaluate to true:
// previously dependsOn: ["userId"] // now dependsOn: !!props.userId
-
provides is now just a function that returns an object, which can add as multiple values to component state simultaneously:
// previously provides: {userId: (queueItemModel) => queueItemModel.get('userId')} // now provides: (queueItemModel) => ({userId: queueItemModel.get('userId')})
As such, the special spread character has been removed.
-
providesModels
, which turned arbitraray data into a listenable model, has been removed. -
The configuration option
queryParamsPropName
, which auto-flattened url parameters nested within a prop, has been removed.