Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@artemisag/mobx-async-store",
"version": "7.1.0",
"version": "7.1.1",
"license": "MIT",
"module": "dist/mobx-async-store.esm.js",
"main": "dist/mobx-async-store.cjs.js",
Expand Down
7 changes: 7 additions & 0 deletions spec/Model.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -943,8 +943,15 @@ describe('Model', () => {
description: 'Example description'
})

const note2 = store.add('notes', {
id: '11',
description: 'Example description'
})

todo.notes.add(note)
note.description = 'something different'
todo.notes.replace([note, note2])
Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this takes a snapshot, which was making dirtyAttributes compare against the latest version of the model instead of the original one.


expect(todo.dirtyAttributes).toEqual(blankSet)
expect(note.dirtyAttributes.size).toEqual(1)
expect(note.dirtyAttributes).toContain('description')
Expand Down
14 changes: 5 additions & 9 deletions spec/Store.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -275,10 +275,6 @@ describe('Store', () => {
})
})

it('has observable data property', () => {
expect(isObservable(store.data)).toBe(true)
})

it('sets network configuration properties', () => {
expect(store.baseUrl).toEqual(mockBaseUrl)
expect(store.defaultFetchOptions).toEqual(mockFetchOptions)
Expand All @@ -300,11 +296,11 @@ describe('Store', () => {

it('initializes data observable', () => {
const map = new Map()
expect(toJS(store.data)).toEqual({
todos: { cache: map, meta: map, records: map },
notes: { cache: map, meta: map, records: map },
categories: { cache: map, meta: map, records: map },
tags: { cache: map, meta: map, records: map }
expect(store.data).toEqual({
todos: { cache: new Map(), meta: new Map(), records: new Map() },
notes: { cache: new Map(), meta: new Map(), records: new Map() },
categories: { cache: new Map(), meta: new Map(), records: new Map() },
tags: { cache: new Map(), meta: new Map(), records: new Map() }
Comment on lines +299 to +303
Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is fora performance improvement (see below)

})
})

Expand Down
2 changes: 1 addition & 1 deletion src/Model.ts
Original file line number Diff line number Diff line change
Expand Up @@ -231,7 +231,7 @@ class Model {

return Object.keys(this.attributes).reduce((dirtyAccumulator, attr) => {
const currentValue = this.attributes[attr]
const previousValue = this.previousSnapshot.attributes[attr]
const previousValue = this.persistedOrFirstSnapshot.attributes[attr]
Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

here's the fix


if (isObject(currentValue)) {
const currentToPreviousDiff = diff(currentValue, previousValue)
Expand Down
13 changes: 6 additions & 7 deletions src/Store.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@ import cloneDeep from 'lodash/cloneDeep'
*/

const mobxAnnotations = {
data: observable,
lastResponseHeaders: observable,
loadingStates: observable,
loadedStates: observable,
Expand Down Expand Up @@ -69,9 +68,9 @@ class Store {
* Stores data by type.
* {
* todos: {
* records: observable.map(), // records by id
* cache: observable.map(), // cached ids by url
* meta: observable.map() // meta information by url
* records: new Map(), // records by id
* cache: new Map(), // cached ids by url
* meta: new Map() // meta information by url
* }
* }
*
Expand Down Expand Up @@ -680,9 +679,9 @@ class Store {
const types = type ? [type] : this.models.map(({ type }) => type)
types.forEach((type) => {
this.data[type] = {
records: observable.map(),
cache: observable.map(),
meta: observable.map()
records: new Map(),
cache: new Map(),
meta: new Map()
Comment on lines +682 to +684
Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

we're not actually observing this anywhere, so it's just a performance hit. It would be cool to observe it though.

}
})
}
Expand Down