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

Add deleteProperty to TrackedObject #35

Closed
wants to merge 1 commit into from
Closed
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
11 changes: 11 additions & 0 deletions addon/-private/object.js
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,17 @@ const proxyHandler = {
return true;
},

deleteProperty(target, prop, receiver) {
Copy link

Choose a reason for hiding this comment

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

Hmm, according to the spec, deleteProperty has no receiver.

Copy link
Contributor

@gnclmorais gnclmorais Mar 23, 2021

Choose a reason for hiding this comment

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

True if you look at an Object’s deleteProperty, but in this case, we’re dealing with a Proxy.

Copy link

Choose a reason for hiding this comment

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

I'm sorry, but I don't really understand. What is "Object's deleteProperty"?
I meant proxyHandler.deleteProperty has no receiver argument, tc39/ecma262#1198

Copy link
Contributor

Choose a reason for hiding this comment

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

I think you’re right, @nag5000. 👍 I got confused.

if (!(prop in target)) { return; }

delete target[prop];

dirtyKey(target, COLLECTION);

// We need to notify this way to make {{each-in}} update
notifyPropertyChange(receiver, '_SOME_PROP_');
},

getPrototypeOf() {
return TrackedObject.prototype;
},
Expand Down
30 changes: 30 additions & 0 deletions tests/unit/object-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -148,4 +148,34 @@ module('TrackedObject', function (hooks) {
}
}
);

reactivityTest(
'Object.deleteProperty works',
class extends Component {
obj = new TrackedObject();

get value() {
return this.obj.foo;
}

update() {
Object.deleteProperty(this.obj, 'foo');
}
}
);

reactivityTest(
'delete works',
class extends Component {
obj = new TrackedObject();

get value() {
return this.obj.foo;
}

update() {
delete this.obj.foo;
}
}
);
});