You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Valentin Mourot edited this page May 2, 2019
·
1 revision
Collection types
Mobile Framework provide some type definitions to help you to write your reducers.
These are not classes, but just type definitions of pure JSON data structures to easily be stored in a cache.
It's up to you to use and manage these simple structures, but Typescript allows you to keep a trace of what type is your data.
Array by Id
With a regular array in JS, which has numbers as key, it's difficult to get an item by its string Id, when you want to store custom data structure like users, resource, etc...
The arrayById type is a way to store an object with id as key.
Just write
constmyDummyArray: IArrayById<Dummy> = {};
Ordered array by Id
Regular ordered arrays in JS must have numbers as key, and objects, which have strings as key, are non-ordered.
The IOrderedArrayById is a combination of an IArrayById with a regular array that store the order of Ids.
To get an ordered array, you just have to go this way :
constmyDummyOrderedArray: IOrderedArrayById<Dummy> = {byId: {},
ids: []
};// Keep `byId` and `ids` consistent !// Get an ordered arraymyDummyOrderedArray.ids.map(id=>myDummyOrderedArray.byId[id])