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

Changeset doesn't set boolean property with a default value #519

Closed
jordpo opened this issue Jul 13, 2020 · 7 comments
Closed

Changeset doesn't set boolean property with a default value #519

jordpo opened this issue Jul 13, 2020 · 7 comments

Comments

@jordpo
Copy link

jordpo commented Jul 13, 2020

Version

3.7.1

Steps to reproduce

Initialize a new Changeset with a boolean property with a default value.

Replication

https://ember-twiddle.com/c3ab24b800d2fbebcde9b0a9bc1cdef2?openFiles=controllers.application%5C.js%2C

Expected Behavior

The property value will toggle from true, to false, back to true.

Actual Behavior

The property toggles initially from false to true, to false, then stays stuck at false

@jordpo
Copy link
Author

jordpo commented Jul 13, 2020

Please note - the setting only breaks when there is a default value that is a boolean. If the property is initialized as undefined, there is no breakage with setting.

@jordpo
Copy link
Author

jordpo commented Jul 13, 2020

I updated the twiddle with a workaround. The error is the ember-changeset implementation of safeSet. If we use the safeSet implementation that validated-changeset uses, the problem seems to be fixed.

UPDATE - unfortunately this doesn't work with the old Ember reactive model so not sure what I can do. We're in a situation where some forms use the old model and others use the newer.

UPDATE - I updated the gist to guard just on boolean types. That gives me the behavior that I want. Not really sure about the root cause.

@jordpo
Copy link
Author

jordpo commented Jul 13, 2020

As an aside, the Readme seems to have incorrect instructions for extending from base and how to pass in options. Changeset takes 4 arguments not 3 and the options is the last arg.

UPDATE - types are also busted. There is no BufferedChangeset export but an EmberChangeset export and the argument issue above.

@snewcomer
Copy link
Collaborator

ref #516

I believe this was fixed in the 3.20-beta series of Ember.js.

ref emberjs/ember.js#18961

Readme seems to have incorrect

Fixed!

@jordpo
Copy link
Author

jordpo commented Jul 21, 2020

Thanks @snewcomer ! Can you explain how the Ember issue fixes the issue that I was seeing with setting boolean values on the changeset?

@snewcomer
Copy link
Collaborator

Basically, there is a "cache" in dev mode that provides helpful debugging/assertions. The "cache" had a value of true and when you tried to set it to false, it just returned the cached value, true.

@jordpo
Copy link
Author

jordpo commented Jul 22, 2020

Thanks. That makes sense. I'll close this issue and wait for 3.20 to be released.

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

2 participants