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

Standarise the fireEvent method interface #399

Conversation

khalilovcmd
Copy link

@khalilovcmd khalilovcmd commented Jul 21, 2018

Why?

When using triggerEvent to fire a change event on <input> element with type="file", those lines call the buildFileEvent which forwards options with its same structure.

Though, buildFileEvent accepts an array: files = [], the documentation doesn't clarify this difference.

I think it will be more natural not to break the interface here by introducing an array argument.

Sample code

let file = new File(['my-content'],'image.png', {
  type: 'image/png',
});
triggerEvent(selector, 'change', [file]); // will work
triggerEvent(selector, 'change',{ files: file }); // will not propagate the value to the event handler

Questions

  1. Should we start writing a test for this file? It think it is a sensitive one to skip tests on.

Alternatives

We could also live with elaborating on this difference in the API.md, to avoid breaking changes.


cc: kudos to @mattdonnelly for pointing this out, and subsequently saving my day.

Copy link
Member

@rwjblue rwjblue left a comment

Choose a reason for hiding this comment

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

Though, buildFileEvent accepts an array: files = [], the documentation doesn't clarify this difference.

buildFileEvent is a private API and should not be used directly, therefore any documentation for this scenario should be in triggerEvent. Can you add additional examples to those inline docs to show how to trigger change on a file input?

Should we start writing a test for this file? I think it is a sensitive one to skip tests on.

Every test we have around eventing is testing fire-event, it is covered fairly well in general but there may be specific event types that are not. We should enumerate the event types and ensure that we have at least one test for each...

let event = buildBasicEvent(type);
let files = options.files || [];
Copy link
Member

Choose a reason for hiding this comment

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

As written, this is a breaking change. As mentioned in the PR description, anyone using triggerEvent for this today must pass an array, if we are going to change this to { files: someArray } as you suggest here, we definitely need to detect if options is already an array...

Copy link
Author

Choose a reason for hiding this comment

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

if we are going to change this to { files: someArray } as you suggest here, we definitely need to detect if options is already an array...

@rwjblue that makes sense. My first thought is to disambiguate this in the documentation itself, but then as a novice user of this add on, I would have expected that the interface to accept { files: someArray }, hence why I felt it might be a more natural (but breaking change) step to standarize it.

@khalilovcmd
Copy link
Author

Thank you @rwjblue for taking a look.

To summarise, I could take these two actions, as you suggested:

Can you add additional examples to those inline docs to show how to trigger change on a file input?

  1. I will add more examples to the documentation of the triggerEvent to elaborate on how to trigger a change event for a file.
  2. Detect if options is already an array.

Does this sound like a good way to move forward?

@rwjblue
Copy link
Member

rwjblue commented Jul 23, 2018

Yep, sounds good to me!

@khalilovcmd khalilovcmd force-pushed the tarek/standarise-the-fireEvent-method-interface branch 3 times, most recently from 0efac39 to 9e6a980 Compare July 25, 2018 08:40
@khalilovcmd
Copy link
Author

@rwjblue does it make sense the way it looks now?

When using `triggerEvent` to fire a `change` event on `<input> element with type="file"`, [those lines](https://github.com/emberjs/ember-test-helpers/blob/8a3614657064efaf13dfe667fe4cfdc14f15f509/addon-test-support/@ember/test-helpers/dom/fire-event.js#L57-L58) call the `buildFileEvent` which forwards `options` with its same structure.

Though, `buildFileEvent` accepts an array: `files = []`, the documentation doesn't clarify this difference.

I think it will be more natural not to break the interface here by introducing an array argument.

Standarise the `fireEvent` method interface

When using `triggerEvent` to fire a `change` event on `<input> element with type="file"`, [those lines](https://github.com/emberjs/ember-test-helpers/blob/8a3614657064efaf13dfe667fe4cfdc14f15f509/addon-test-support/@ember/test-helpers/dom/fire-event.js#L57-L58) call the `buildFileEvent` which forwards `options` with its same structure.

Though, `buildFileEvent` accepts an array: `files = []`, the documentation doesn't clarify this difference.

I think it will be more natural not to break the interface here by introducing an array argument.

Standarise the `fireEvent` method interface

When using `triggerEvent` to fire a `change` event on `<input> element with type="file"`, [those lines](https://github.com/emberjs/ember-test-helpers/blob/8a3614657064efaf13dfe667fe4cfdc14f15f509/addon-test-support/@ember/test-helpers/dom/fire-event.js#L57-L58) call the `buildFileEvent` which forwards `options` with its same structure.

Though, `buildFileEvent` accepts an array: `files = []`, the documentation doesn't clarify this difference.

I think it will be more natural not to break the interface here by introducing an array argument.

Apply PR feedback

1. Added an example to the documentation of the `triggerEvent` to elaborate on how to trigger a change event for a file.
2. Added logic for detecting if options is already an array.

This commit allows us to avoid introducing breaking changes, and maintain an expectation of providing `files` array in the `options` object for the `triggerEvent` method.

Standarise the `fireEvent` method interface

When using `triggerEvent` to fire a `change` event on `<input> element with type="file"`, [those lines](https://github.com/emberjs/ember-test-helpers/blob/8a3614657064efaf13dfe667fe4cfdc14f15f509/addon-test-support/@ember/test-helpers/dom/fire-event.js#L57-L58) call the `buildFileEvent` which forwards `options` with its same structure.

Though, `buildFileEvent` accepts an array: `files = []`, the documentation doesn't clarify this difference.

I think it will be more natural not to break the interface here by introducing an array argument.

Apply PR feedback

1. Added an example to the documentation of the `triggerEvent` to elaborate on how to trigger a change event for a file.
2. Added logic for detecting if options is already an array.

This commit allows us to avoid introducing breaking changes, and maintain an expectation of providing `files` array in the `options` object for the `triggerEvent` method.

Fix lint offense

Fix lint offense

Standarise the `fireEvent` method interface

When using `triggerEvent` to fire a `change` event on `<input> element with type="file"`, [those lines](https://github.com/emberjs/ember-test-helpers/blob/8a3614657064efaf13dfe667fe4cfdc14f15f509/addon-test-support/@ember/test-helpers/dom/fire-event.js#L57-L58) call the `buildFileEvent` which forwards `options` with its same structure.

Though, `buildFileEvent` accepts an array: `files = []`, the documentation doesn't clarify this difference.

I think it will be more natural not to break the interface here by introducing an array argument.

Apply PR feedback

1. Added an example to the documentation of the `triggerEvent` to elaborate on how to trigger a change event for a file.
2. Added logic for detecting if options is already an array.

This commit allows us to avoid introducing breaking changes, and maintain an expectation of providing `files` array in the `options` object for the `triggerEvent` method.

Fix lint offense

Standarise the `fireEvent` method interface

When using `triggerEvent` to fire a `change` event on `<input> element with type="file"`, [those lines](https://github.com/emberjs/ember-test-helpers/blob/8a3614657064efaf13dfe667fe4cfdc14f15f509/addon-test-support/@ember/test-helpers/dom/fire-event.js#L57-L58) call the `buildFileEvent` which forwards `options` with its same structure.

Though, `buildFileEvent` accepts an array: `files = []`, the documentation doesn't clarify this difference.

I think it will be more natural not to break the interface here by introducing an array argument.

Apply PR feedback

1. Added an example to the documentation of the `triggerEvent` to elaborate on how to trigger a change event for a file.
2. Added logic for detecting if options is already an array.

This commit allows us to avoid introducing breaking changes, and maintain an expectation of providing `files` array in the `options` object for the `triggerEvent` method.

Fix lint offense

Fix lint offense

Standarise the `fireEvent` method interface

When using `triggerEvent` to fire a `change` event on `<input> element with type="file"`, [those lines](https://github.com/emberjs/ember-test-helpers/blob/8a3614657064efaf13dfe667fe4cfdc14f15f509/addon-test-support/@ember/test-helpers/dom/fire-event.js#L57-L58) call the `buildFileEvent` which forwards `options` with its same structure.

Though, `buildFileEvent` accepts an array: `files = []`, the documentation doesn't clarify this difference.

I think it will be more natural not to break the interface here by introducing an array argument.

Apply PR feedback

1. Added an example to the documentation of the `triggerEvent` to elaborate on how to trigger a change event for a file.
2. Added logic for detecting if options is already an array.

This commit allows us to avoid introducing breaking changes, and maintain an expectation of providing `files` array in the `options` object for the `triggerEvent` method.

Fix lint offense

Fix lint offense

Fix identation in the docs

Fix lint issues
@khalilovcmd khalilovcmd force-pushed the tarek/standarise-the-fireEvent-method-interface branch from 9e6a980 to 5ddfe54 Compare July 25, 2018 13:45
let event = buildBasicEvent(type);
let files = Array.isArray(options) ? options : options.files || [];
Copy link
Member

Choose a reason for hiding this comment

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

Should we issue a deprecation or something when we do this coercion?

I'm just thinking that over time we probably only want to support one form...

*
* // passing an array of files
* let file = new File(['text file'], 'text.txt', { type: 'text/plain' });
* await triggerEvent('input:file', 'change', [file]);
Copy link
Member

Choose a reason for hiding this comment

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

I think ultimately, we should only have one format here (probably the { files: [] } one?)...

@rwjblue
Copy link
Member

rwjblue commented Aug 6, 2018

@khalilovcmd - Had a chance to review those questions?

@rwjblue
Copy link
Member

rwjblue commented Aug 7, 2018

Will need to address merge conflicts from docs changes made in #340

@rwjblue
Copy link
Member

rwjblue commented Sep 27, 2018

@khalilovcmd - I'd still love to land this, any chance you mind have time to rebase and clean up soon?

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.

None yet

2 participants