Releases: iunu/mobx-async-store
It's been a while!
What's Changed
- add loadingStates to store by @jondayton in #153
- Missed a couple of transactions, and it's better to use runInAction by @sd in #169
- Less talk, more action by @sd in #170
- License info by @sd in #183
- Add ability to clear cache by type in Store by @CalCorbin in #195
- Add clearCache documentation to readme by @CalCorbin in #198
- add testing utilities by @jondayton in #202
- add check for dirtyAttributes if a key is removed by @jondayton in #203
- Tag test factories and mock servers to allow detecting misconfigurations by @sd in #204
- Allow MockServer to accept response overrides in the constructor by @sd in #206
- remove yuidoc from dependencies by @jondayton in #218
- update dependencies by @jondayton in #224
- allow meta attribute for arrays and consolidate adding model methods by @jondayton in #241
- add meta to cache by @jondayton in #251
- fix loading states observables by @jondayton in #253
- add a warning for a double call by @jondayton in #254
- rollback mobx to 6.3.5 by @jackiekircher in #255
- retry failed fetches by @jackiekircher in #252
- don't use duplicate ids for findMany by @jondayton in #275
- fix findMany recursive ids being replaced in queryParams object by @jondayton in #277
- clean up tests by @jondayton in #274
- add bulkSave and req params to MockServer by @jondayton in #285
- add loadedStates property by @jondayton in #313
- bump version for dependency updates by @jondayton in #372
Full Changelog: v4.0.0...v4.9.1
Update to mobx 6
This does not change any API, but may cause conflicts / errors if you are using mobx < 6.0 in your application. For information on how to upgrade from mobx 5 to 6, see the mobx docs.
Changes to `add`
store.add
has been very inconsistent in the past. First, it accepted any properties. Second, it would override relationships as simple properties. This could lead to some strange situations.
Consider a basic model Todo
with relationships Category
and Note
class Category extends Model {
static type = 'categories'
}
class Note extends Model {
static type = 'notes'
}
class Todo extends Model {
static type = 'todos'
@attribute(String) title = ''
@observable highlighted
@relatedToMany notes
@computed get capTitle () {
return this.title.toUpperCase()
}
}
store.add
could be used to set attributes, but everything else (relationships, computed properties, and non-defined properties) would be set as an unobserved properties. When accessing the object, these would be returned as mishmash of observed attributes and properties, and unobserved properties.
const todo = store.add('todos, {
title: 'Take out trash',
assigneeName: 'Me',
highlighted: true,
notes: [{ id: '1', type: 'notes' }],
category: store.getOne('categories', '1'),
capTitle: 'Take in Trash'
})
$> todo.title
=> Todo {
title: 'Take out trash', // observed attribute
highlighted: true, // observed property (will not be serialized)
assigneeName: 'Me', // unobserved text (not defined as an attribute)
notes: [{ id: '1', type: 'notes' }] // unobserved array with an object (relationship definition is overridden)
category: Category { id: '1' } // unobserved Category object (relationship definition is overridden)
capTitle: 'Take in Trash' // unobserved text (computed property is overridden)
}
With these changes, add
will work differently:
- it accepts attributes as well as relationships, and sets them correctly
- relationships can be passed as either the id and type of an object, or the object itself
- it will not accept anything that is not an attribute or a relationship
const todo = store.add('todos, {
title: 'Take out trash',
assigneeName: 'Me',
highlighted: true,
notes: [{ id: '1', type: 'notes' }],
category: store.getOne('categories', '1'),
capTitle: 'Take in Trash'
})
$> todo.title
=> Todo {
title: 'Take out trash', // observed attribute
highlighted: undefined, // observed property, can only be set directly (not by using `add`)
assigneeName: undefined, // unobserved property, can only be set directly (not by using `add`)
notes: [Note { id: '1' }], // observed relationship array with a Note object
category: Category { id: '1' }, // observed relationship with a Category object
capTitle: 'TAKE OUT TRASH' // computed property (cannot be overridden)
}
mobx upgrade
v3.7.0 upgrade mobx to most recent 5.x version (#101)
v3.6.5: Revert "update add to accept relationships (#99)"
This reverts commit e1ff2e119a4a1435adb5f9a1331681fafd237e9c.
3.4.1
Internal fixes
Improved use of inverse relationships as a fallback for missing data.
Batch and group transactions
v3.2.0 extensions instead of customExtensions (#75)
Server Errors!
Adds server errors directly to their corresponding attributes in models.
Previously we had made the decision to lump all server errors onto a "server" attribute so that they would at least be accessible. Now, when errors come back from the API we parse the source pointer for each error to determine which attribute the error is for and add it in the same manner as our model validations. This is a breaking change, so 3.0 has arrived!
This also support errors for create/update requests using the JSONApi bulk extension. When these errors are returned, the pointer will contain an index that corresponds to the payload of the original request which is used to determine which object in the store the errors should be assigned to.
return a promise for findAll
This contains a breaking change for findAll
, one of the most commonly-used methods in the past. findAll
returns a promise if it executes a fetch, but an array if it uses the cache. this is fine if fromServer
is explicit, but otherwise the return object is ambiguous.