-
Notifications
You must be signed in to change notification settings - Fork 4.1k
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
Component utils #222
Conversation
129d419
to
56625b5
Compare
*/ | ||
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 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Waiting, Rich-Harris/simulant#11 (comment)
There was a problem hiding this comment.
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 👍
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Woop, updating.
// - assign our own params | ||
|
||
const DONT_USE_THESE_PARAMS = {} | ||
const event = simulant(eventType, DONT_USE_THESE_PARAMS) |
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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.
🐓 Looks great! |
* @param {Object} [data] Additional event data. | ||
* @returns {Object} The event | ||
*/ | ||
export const keyDown = (node, data) => fire(node, 'keydown', data) |
There was a problem hiding this comment.
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)
There was a problem hiding this comment.
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.
8c5705d
to
04ac8fa
Compare
04ac8fa
to
1f03270
Compare
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 ofsimulant
.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.