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

x-toggle toggles on click when the onToggle action does not update the value #91

Closed
lolmaus opened this issue Sep 13, 2017 · 6 comments
Closed
Labels

Comments

@lolmaus
Copy link
Collaborator

lolmaus commented Sep 13, 2017

How to reproduce

{
  value: false,
  
  actions: {
    toggle () {}
  }
}
<p>value: {{value}}</p>

{{x-toggle value=value onToggle=(action 'toggle')}}

image

Now click the toggle.

What I expect to happen

The component should not toggle because the action does not update the value.

What actually happens

image

The component does toggle, the value and the component's state are out of sync.

Reproduction

https://ember-twiddle.com/85bcda587638b642fcf254d550488899?numColumns=2&openFiles=controllers.application.js%2Ctemplates.application.hbs

Notes

Happens only for clicking. Dragging works correctly: the component toggles only when the action updates the value.

@lolmaus lolmaus added the bug label Sep 13, 2017
@lolmaus
Copy link
Collaborator Author

lolmaus commented Sep 13, 2017

I've just tried one-way-checkbox from ember-one-way-controls and it has the same problem. 😭

https://ember-twiddle.com/3ce9e7f1dd2a09ae7c9219a8031e69be?numColumns=2&openFiles=controllers.application.js%2Ctemplates.application.hbs

lolmaus added a commit to lolmaus/ember-toggle that referenced this issue Sep 13, 2017
@scottkidder
Copy link
Contributor

Just ran into this as well.

@webark
Copy link
Contributor

webark commented Sep 15, 2017

are you sure this is a bug? If you did a standard checkbox input, and set up a one way binding with it, the check box would trigger but if you didn't update the value, it wouldn't update.. having it not update, you'd have resetup two way binding. Right?

@lolmaus
Copy link
Collaborator Author

lolmaus commented Sep 15, 2017

@webark, the <input> element is a remnant of 20th century when the only way to communicate with the backend was to submit a form. At that time, nobody thought about DDAU. Two-way binding was the only way. Actually, there was no binding at all, because there was no other property to bind to. In other words, the internal checked property of the <input> element was the only source of truth.

With Ember, the primary source of truth is a property that you pass as value. The <input>'s checked property must always be in sync with it.

Also, ember-toggle tries to follow DDAU strictly. The value is bound to the <input>. But this binding is one-way: since v3 (I think), it is no longer capable of mutating the value. All it can do is to report back to the app: "the user has flicked the toggle to <boolean>".

If the app decides not to change value in response to this user action, yet the <input>'s state has changed, then the app's internal state has become inconsistent. This should never happen.

@knownasilya Are we on the same page?

scottkidder added a commit to scottkidder/ember-toggle that referenced this issue Sep 15, 2017
@scottkidder
Copy link
Contributor

I think I have a failing test for this in #94

scottkidder added a commit to scottkidder/ember-toggle that referenced this issue Sep 15, 2017
lolmaus added a commit to lolmaus/ember-toggle that referenced this issue Sep 18, 2017
…tion does not update the value - panning should not enable when the action does not update the value
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

3 participants