Skip to content
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

Reduce property notif change with tracked-built-ins #517

Open
wants to merge 5 commits into
base: master
Choose a base branch
from
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
17 changes: 14 additions & 3 deletions addon/index.js
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
import { assert } from '@ember/debug';
import { dependentKeyCompat } from '@ember/object/compat';
import { BufferedChangeset } from 'validated-changeset';
import { BufferedChangeset, Change, keyInObject } from 'validated-changeset';
import ArrayProxy from '@ember/array/proxy';
import ObjectProxy from '@ember/object/proxy';
import { notifyPropertyChange } from '@ember/object';
import { tracked } from 'tracked-built-ins';
import mergeDeep from './utils/merge-deep';
import isObject from './utils/is-object';
import { tracked } from '@glimmer/tracking';
import { get as safeGet, set as safeSet } from '@ember/object';

const CHANGES = '_changes';
Expand Down Expand Up @@ -133,6 +133,17 @@ export class EmberChangeset extends BufferedChangeset {
* Returns value or error
*/
_setProperty({ key, value, oldValue }) {
let changes = this[CHANGES];

// Happy path: update change map.
if (oldValue !== value) {
this.setDeep(changes, key, new Change(value), {
safeSet: this.safeSet,
});
} else if (keyInObject(changes, key)) {
this._deleteKey(CHANGES, key);
}

super._setProperty({ key, value, oldValue });

notifyPropertyChange(this, key);
Expand Down Expand Up @@ -181,7 +192,7 @@ export class EmberChangeset extends BufferedChangeset {

// we want mutation on original object
// @tracked
this[CONTENT] = this.mergeDeep(content, changes, { safeGet, safeSet });
this.mergeDeep(content, changes, { safeGet, safeSet });
}

this[PREVIOUS_CONTENT] = oldContent;
Expand Down
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@
"@glimmer/tracking": "^1.0.1",
"ember-auto-import": "^1.5.2",
"ember-cli-babel": "^7.19.0",
"tracked-built-ins": "^1.0.2",
"validated-changeset": "~0.14.2"
},
"devDependencies": {
Expand Down
Loading