Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

Bye bye simulate #2704

Merged
merged 4 commits into from
Oct 1, 2016
Merged

Bye bye simulate #2704

merged 4 commits into from
Oct 1, 2016

Conversation

marcandre
Copy link
Contributor

@marcandre marcandre commented Sep 25, 2016

This PR removes the dependency on simulate, which is old, unmaintained and incomplete.

Replacing costs about 5 lines of code...

It also adds the input event to the prototype version.

Builds on #2697

@koenpunt
Copy link
Collaborator

👍 Looks good, will review in the morning.

Copy link
Collaborator

@koenpunt koenpunt left a comment

Choose a reason for hiding this comment

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

In general I'm really pro the removal of the extra event dependency, so that's great, thanks! Just see my notes below.

Chosen.trigger(@form_field, 'input')
Chosen.trigger(@form_field, 'change')

@trigger: (element, eventType) ->
Copy link
Collaborator

Choose a reason for hiding this comment

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

Having trigger as public method shouldn't be necessary. But this probably has been done so the method is available in the tests as well?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Right. Should I call it _trigger instead?

Chosen.trigger(@form_field, 'change')

@trigger: (element, eventType) ->
if (document.createEventObject) # Old IE:
Copy link
Collaborator

Choose a reason for hiding this comment

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

if statements should be written without parens (I know, there are some conditions that do use parens, but they just slipped through the cracks I guess)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

No problem

expect(container.hasClassName("chosen-container-active")).toBe true

#select an item
container.select(".active-result").last().simulate("mouseup")
Chosen.trigger(container.select(".active-result").last(), 'mouseup');
Copy link
Collaborator

@koenpunt koenpunt Sep 26, 2016

Choose a reason for hiding this comment

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

Nitpicky, but inconsistent quote usage. On multiple locations, but marking them all feels too extreme.

And yes I know it's hypocritical, because we use single and double quotes randomly around the library, but I still strive for some consistency.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

👍 should not have switched them

@@ -27,11 +27,11 @@ describe "Basic setup", ->
expect($F(select)).toBe ""

container = div.down(".chosen-container")
container.simulate("mousedown") # open the drop
Chosen.trigger(container, "mousedown") # open the drop
Copy link
Collaborator

Choose a reason for hiding this comment

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

this is not a good idea, because Chosen.trigger is not a full-fledged implementation of triggering builtin events (it always relies on the Event class, while many DOM events are using subclasses with extra properties)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

So what is a better idea?

Copy link
Collaborator

Choose a reason for hiding this comment

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

Well, as Chosen does not need a full-fledged event triggering system (as it does not need to trigger mouse events), the simpler would probably be to keep using an external library for that in the testsuite

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I arrived at the same conclusion 😄

@trigger: (element, eventType) ->
if (document.createEventObject) # Old IE:
element.fireEvent("on#{eventType}", document.createEventObject());
else # Modern way:
Copy link
Collaborator

Choose a reason for hiding this comment

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

you should detect support for the modern way instead (detecting dispatchEvent), to use the modern way when multiple ways are available. fireEvent should be a fallback only.

Btw, you should also write the code using createEvent() and initEvent when dispatchEvent is available but not the Event constructor (i.e. the intermediate API)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Ok

@marcandre
Copy link
Contributor Author

Tweaked as per comments, and reorganized the commits to make more sense.

@marcandre marcandre mentioned this pull request Sep 27, 2016
@marcandre marcandre force-pushed the bye_bye_simulate branch 2 times, most recently from a6b7f46 to 51bf72b Compare September 27, 2016 17:59
@marcandre
Copy link
Contributor Author

Ok, hopefully third time's the charm.

No more Chosen.trigger, dependency on simulate is kept only for testing, and prototype version supports 5 year old Safari and al., while being forward compatible by not using initEvent and al. when possible (those are deprecated).

evt.initEvent(eventType, true, true);
element.dispatchEvent(evt)
else
document.createEventObject # Old IE:
Copy link
Collaborator

Choose a reason for hiding this comment

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

this line is useless

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Indeed. Fixed

@@ -229,7 +229,7 @@
<td>change</td>
<td>
<p>Chosen triggers the standard DOM event whenever a selection is made (it also sends a <code class="language-javascript">selected</code> or <code class="language-javascript">deselected</code> parameter that tells you which option was changed).</p>
<p><strong>Note:</strong> in order to use change in the Prototype version, you have to include the <a href="https://github.com/kangax/protolicious/blob/5b56fdafcd7d7662c9d648534225039b2e78e371/event.simulate.js">Event.simulate</a> class. The selected and deselected parameters are not available for Prototype.</p>
<p>The selected and deselected parameters are not available for Prototype.</p>
Copy link
Collaborator

Choose a reason for hiding this comment

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

<strong>Note:</strong> should be kept

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Fixed

@koenpunt
Copy link
Collaborator

koenpunt commented Oct 1, 2016

@stof anything else?

@koenpunt koenpunt merged commit 439a711 into harvesthq:master Oct 1, 2016
@koenpunt
Copy link
Collaborator

koenpunt commented Oct 1, 2016

Thanks again, @marcandre 💯

@marcandre
Copy link
Contributor Author

👍 I'm pretty impressed by the committer team!

@marcandre
Copy link
Contributor Author

Is it possible to make a release with this?

@marcandre marcandre deleted the bye_bye_simulate branch October 1, 2016 13:37
@koenpunt
Copy link
Collaborator

koenpunt commented Oct 1, 2016

I'm collecting as much small bugfixes as possible for a new release, but I expect to release 1.7.0 somewhere next week.

@marcandre
Copy link
Contributor Author

I would still very much appreciate a release...

@koenpunt
Copy link
Collaborator

@marcandre I understand, and it has been more than a week now, but there are still quite some PR's that I'd like to see merged for the 1.7.0 release.
Truth is though that I can't make all decisions on my own, and not all maintainers are as active as I have been for the past month (which is fine, because open source), which causes that not everything goes as quick as I want it to go.
But if you like, reviews on the last 8 pull requests are more than welcome, which can eventually speed up the review process for the other maintainers.

@koenpunt
Copy link
Collaborator

@marcandre took some time, but as there was no progress since a few months I decided to put out a release. So 1.7.0 is now available.

@marcandre
Copy link
Contributor Author

Thanks @koenpunt

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

Successfully merging this pull request may close these issues.

3 participants