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

Regression in behavior of delete after 3.13 from mandatory setters #18856

Closed
chriskrycho opened this issue Apr 1, 2020 · 4 comments
Closed

Comments

@chriskrycho
Copy link
Contributor

In 405d423, we introduced mandatory setters to native properties. Previously, users could call delete this.foo and then later call set(this, 'foo', 'some value'), and it would work correctly. Because the setters are set on the instance (as they must be), this no longer works: if a user calls delete this.foo, it deletes the getter and setter, meaning that all future calls to set(this, 'foo', ...) fail.

Workaround: using set(this, 'foo', undefined).

Related: #18769

@rwjblue
Copy link
Member

rwjblue commented May 23, 2020

The mandatory setter changes have landed now, we should reevaluate...

@knownasilya
Copy link
Contributor

Wonder if this is fixed.

@rwjblue
Copy link
Member

rwjblue commented Oct 12, 2020

@chriskrycho - Mind double checking (or throwing together a repro that we could use to check in on this in the future)?

@chriskrycho
Copy link
Contributor Author

Seems to be fixed!

test code to demonstrate

controllers/application.js:

import Controller from "@ember/controller";
import { set } from "@ember/object";

export default class ApplicationController extends Controller {
  foo;

  constructor() {
    super(...arguments);
    set(this, "foo", "huh");
  }

  baleted = () => {
    delete this.foo;
  };

  setItBack = () => {
    set(this, "foo", "hey, it's back!");
  };
}

templates/application.hbs:

<h2 id="title">
  baleted
</h2>
<p>
  <code>
    this.foo
  </code>
  is
  {{describe this.foo}}
</p>
<div>
  <button {{on "click" this.baleted}}>
    BALETED
  </button>
</div>
<div>
  <button {{on "click" this.setItBack}}>
    Put it back
  </button>
</div>

helpers/describe.js:

import { helper } from "@ember/component/helper";

export default helper(function describe([value] /*, hash*/) {
  return value === undefined ? "undefined" : JSON.stringify(value);
});

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants