diff --git a/package.json b/package.json index f9f0675c..9de8e8e3 100644 --- a/package.json +++ b/package.json @@ -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", diff --git a/spec/Model.spec.ts b/spec/Model.spec.ts index 668f6f93..fcc4995d 100644 --- a/spec/Model.spec.ts +++ b/spec/Model.spec.ts @@ -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]) + expect(todo.dirtyAttributes).toEqual(blankSet) expect(note.dirtyAttributes.size).toEqual(1) expect(note.dirtyAttributes).toContain('description') diff --git a/spec/Store.spec.ts b/spec/Store.spec.ts index 0bbb25c7..62a3e538 100644 --- a/spec/Store.spec.ts +++ b/spec/Store.spec.ts @@ -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) @@ -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() } }) }) diff --git a/src/Model.ts b/src/Model.ts index 8b6d9946..3e8d0268 100644 --- a/src/Model.ts +++ b/src/Model.ts @@ -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] if (isObject(currentValue)) { const currentToPreviousDiff = diff(currentValue, previousValue) diff --git a/src/Store.ts b/src/Store.ts index d3d48d0f..2d257c8e 100644 --- a/src/Store.ts +++ b/src/Store.ts @@ -15,7 +15,6 @@ import cloneDeep from 'lodash/cloneDeep' */ const mobxAnnotations = { - data: observable, lastResponseHeaders: observable, loadingStates: observable, loadedStates: observable, @@ -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 * } * } * @@ -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() } }) }