-
Notifications
You must be signed in to change notification settings - Fork 1
fix dirtyAttributes to look at persisted values rather than latest and remove observability from data property on store #459
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -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() } | ||
|
Comment on lines
+299
to
+303
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This is fora performance improvement (see below) |
||
| }) | ||
| }) | ||
|
|
||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -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] | ||
|
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. here's the fix |
||
|
|
||
| if (isObject(currentValue)) { | ||
| const currentToPreviousDiff = diff(currentValue, previousValue) | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -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() | ||
|
Comment on lines
+682
to
+684
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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. |
||
| } | ||
| }) | ||
| } | ||
|
|
||
There was a problem hiding this comment.
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
dirtyAttributescompare against the latest version of the model instead of the original one.