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

Proposed fix for breakage in "Fix echo update" #52

Merged
merged 1 commit into from Mar 3, 2016
Merged

Proposed fix for breakage in "Fix echo update" #52

merged 1 commit into from Mar 3, 2016

Conversation

ghost
Copy link

@ghost ghost commented Feb 28, 2016

No description provided.

@ghost ghost mentioned this pull request Feb 28, 2016
@ghost
Copy link
Author

ghost commented Feb 28, 2016

I should add a test that tests the ability to sanitize inputs set through the binding.

@ghost
Copy link
Author

ghost commented Feb 28, 2016

Added a test, but unsure if test tests the right thing

@@ -86,12 +86,16 @@ const OneWayInputComponent = Component.extend({
},

init() {
this._super(...arguments);
Copy link
Contributor

Choose a reason for hiding this comment

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

_super should always happen before touching this

Copy link
Author

Choose a reason for hiding this comment

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

The problem is that with version 2.0 (and possibly 1.13) the didReceiveAttrs hook gets called during the _super call. That would mean the _processNewValue gets called before _sanitezedValue has been set.

Copy link
Contributor

Choose a reason for hiding this comment

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

Yes, that was fixed with emberjs/ember.js#12260 and was backported to 1.13.9 and 2.0.1. What version were you testing with?

Copy link
Author

Choose a reason for hiding this comment

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

2.0.3

Copy link
Contributor

Choose a reason for hiding this comment

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

O_o

Copy link
Author

Choose a reason for hiding this comment

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

Seeing that reaction, I'll double check it.

Copy link
Author

Choose a reason for hiding this comment

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

Ember.VERSION === '2.0.3'

init() {
  this._super(...arguments);
  let value = get(this, 'paramValue') || get(this, 'value');
  set(this, 'value', value);

  debugger;
  this._sanitizedValue = get(this, 'value') || get(this, 'checked');
},

didReceiveAttrs() {
  debugger;
  this._super(...arguments);
  this._processNewValue.call(this, undefined, get(this, get(this, 'appropriateAttr')));
}

The debugger in didReceiveAttrs gets hit first.

Copy link
Contributor

Choose a reason for hiding this comment

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

No, I think you are correct: http://rwjblue.jsbin.com/vexodub/edit?html,js,output

This was listed as fixed in the CHANGELOG for 2.0.1 though, so I must have screwed something up 😞

Copy link
Contributor

Choose a reason for hiding this comment

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

Well, apparently I fail at computers for the day. I guess this is ok as long as you leave a comment explaining why (// @rwjblue sucks at releasing and 2.0.3 contains a dumb bug)...

Copy link
Author

Choose a reason for hiding this comment

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

I will for sure add that comment! 👍

@rwjblue
Copy link
Contributor

rwjblue commented Feb 29, 2016

The test added here looks good (and does test a previously untested scenario), but wasnt' quite the scenario that I was thinking of. I was thinking more along the lines of:

test('It triggers sanitizeInput on value binding change', function(assert) {
  this.on('sanitize', (value) => value && value.toUpperCase());
  this.set('value', 'foo');
  this.render(hbs`{{one-way-input value=value
    sanitizeInput=(action 'sanitize')
    update=(action (mut foo))}}`);

  // initial render with an invalid value gets sanitized and calls update
  assert.equal(this.get('value'), 'FOO');

  this.set('value', 'bar');
  // set triggered a rerender, which sanitized the input and called update
  assert.equal(this.get('value'), 'BAR');
});

@ghost
Copy link
Author

ghost commented Mar 3, 2016

@homu r+

@homu
Copy link
Contributor

homu commented Mar 3, 2016

📌 Commit e1c199d has been approved by martndemus

@homu
Copy link
Contributor

homu commented Mar 3, 2016

⚡ Test exempted - status

@homu homu merged commit e1c199d into DavyJonesLocker:master Mar 3, 2016
homu added a commit that referenced this pull request Mar 3, 2016
Proposed fix for breakage in "Fix echo update"

None
@ghost ghost deleted the fix-echo-updates branch March 3, 2016 16:31
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

Successfully merging this pull request may close these issues.

3 participants