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

Component utils #222

Merged
merged 3 commits into from
Apr 27, 2016
Merged

Component utils #222

merged 3 commits into from
Apr 27, 2016

Conversation

levithomason
Copy link
Member

@levithomason levithomason commented Apr 26, 2016

This PR is a breakout of #206. It adds utils that facilitate writing and testing components without Semantic UI jQuery plugins.

The source is well annotated so I'm skipping comment annotations on this one. Here is the summary:

childrenUtils

With our transition, we also are implementing our v.1.0 component API. This means no more className use for component behavior and styling. We extend child utils to facilitate some of this.

domEvent

With jQuery out of the picture we now need to handle events. Both creating and dispatching them in tests. Simulant gives a cross browser way to create real browser events (we're in phantomjs). domEvent is our wrapper implementation of simulant.

syntheticEvent

Real browser events alone won't do, our tests rely on React's synthetic events. This util is just that, basically an enum of synthetic events and their shape. These are used to test component events.

*/
export const fire = (node, eventType, data = {}) => {
const DOMNode = typeof node === 'string' ? document.querySelector(node) : node
// TODO remove hack once merged: https://github.com/Rich-Harris/simulant/pull/11
Copy link
Member Author

@levithomason levithomason Apr 26, 2016

Choose a reason for hiding this comment

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

Copy link
Contributor

Choose a reason for hiding this comment

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

Looks like he merged that in 👍

Copy link
Member Author

Choose a reason for hiding this comment

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

Woop, updating.

This was referenced Apr 26, 2016
// - assign our own params

const DONT_USE_THESE_PARAMS = {}
const event = simulant(eventType, DONT_USE_THESE_PARAMS)
Copy link
Contributor

Choose a reason for hiding this comment

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

Just curious - What is DONT_USE_THESE_PARAMS doing? Seems like an intense name

Copy link
Member Author

Choose a reason for hiding this comment

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

Aye, intense for exactly that reason. The bug I fixed in simulant was centered around passing in event data in that arg. Wanted to ensure no one ever put data in that object, it had to remain empty.

With the bug fixed merged and shipped, I can remove this now.

@kyleturco
Copy link
Contributor

🐓 Looks great!

* @param {Object} [data] Additional event data.
* @returns {Object} The event
*/
export const keyDown = (node, data) => fire(node, 'keydown', data)
Copy link
Member

Choose a reason for hiding this comment

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

Just because I have to whenever I see repeated code like this:

const fire = curry((event, node, data) => { ... })

export const keyDown = fire('keydown')
export const click = fire('click')

click(node, data)

Copy link
Member Author

Choose a reason for hiding this comment

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

May implement this on the cleanup PR once the breakout is done being merged.

@levithomason levithomason force-pushed the feature/component-utils branch 2 times, most recently from 8c5705d to 04ac8fa Compare April 27, 2016 17:09
@levithomason levithomason merged commit e6481de into master Apr 27, 2016
@levithomason levithomason deleted the feature/component-utils branch April 27, 2016 17:31
@levithomason levithomason mentioned this pull request May 24, 2016
24 tasks
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