Skip to content

Commit

Permalink
Merge pull request #105 from PolymerElements/ccompile
Browse files Browse the repository at this point in the history
Improve Closure type annotations
  • Loading branch information
aomarks authored Jun 20, 2019
2 parents 17cb1e4 + ac69673 commit 262ebf3
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 2 deletions.
19 changes: 19 additions & 0 deletions mock-interactions.js
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ const HAS_NEW_TOUCH = (() => {
* Returns the (x,y) coordinates representing the middle of a node.
*
* @param {!Element} node An element.
* @return {{x: number, y:number}}
*/
export function middleOfNode(node) {
const bcr = node.getBoundingClientRect();
Expand All @@ -43,6 +44,7 @@ export function middleOfNode(node) {
* Returns the (x,y) coordinates representing the top left corner of a node.
*
* @param {!Element} node An element.
* @return {{x: number, y:number}}
*/
export function topLeftOfNode(node) {
const bcr = node.getBoundingClientRect();
Expand All @@ -57,6 +59,7 @@ export function topLeftOfNode(node) {
* @param {!Array<{ x: number, y: number }>} xyList A list of (x,y) coordinate
* objects.
* @param {!Element} node A target element node.
* @return {!Array<!Touch>}
*/
export function makeTouches(xyList, node) {
let id = 0;
Expand All @@ -78,6 +81,7 @@ export function makeTouches(xyList, node) {
* TouchEvent.
* @param {!Element} node The target element node for the generated
* TouchEvent to be dispatched on.
* @return {undefined}
*/
export function makeSoloTouchEvent(type, xy, node) {
xy = xy || middleOfNode(node);
Expand Down Expand Up @@ -116,6 +120,7 @@ export function makeSoloTouchEvent(type, xy, node) {
* @param {{ x: number, y: number }} xy The (x,y) coordinates the mouse event
* should be fired from.
* @param {!Element} node The node to fire the event on.
* @return {undefined}
*/
export function makeMouseEvent(type, xy, node) {
const props = {
Expand Down Expand Up @@ -163,6 +168,7 @@ export function makeMouseEvent(type, xy, node) {
* @param {Object} toXY The (x,y) coordinates the dragging should end at.
* @param {?number=} steps Optional. The numbers of steps in the move motion.
* If not specified, the default is 5.
* @return {undefined}
*/
export function move(node, fromXY, toXY, steps) {
steps = steps || 5;
Expand Down Expand Up @@ -206,6 +212,7 @@ export function track(target, dx, dy, steps) {
* @param {!Element} node The node to fire the event on.
* @param {{ x: number, y: number }=} xy Optional. The (x,y) coordinates the
* mouse event should be fired from.
* @return {undefined}
*/
export function down(node, xy) {
xy = xy || middleOfNode(node);
Expand All @@ -231,6 +238,7 @@ export function up(node, xy) {
* @param {!Element} node The node to fire the click event on.
* @param {{ x: number, y: number }=} xy Optional. The (x,y) coordinates the
* mouse event should be fired from.
* @return {undefined}
*/
export function click(node, xy) {
xy = xy || middleOfNode(node);
Expand All @@ -243,6 +251,7 @@ export function click(node, xy) {
* @param {!Element} node The node to fire the click event on.
* @param {{ x: number, y: number }=} xy Optional. The (x,y) coordinates the
* touch event should be fired from.
* @return {undefined}
*/
export function touchstart(node, xy) {
xy = xy || middleOfNode(node);
Expand All @@ -254,6 +263,7 @@ export function touchstart(node, xy) {
* @param {!Element} node The node to fire the click event on.
* @param {{ x: number, y: number }=} xy Optional. The (x,y) coordinates the
* touch event should be fired from.
* @return {undefined}
*/
export function touchend(node, xy) {
xy = xy || middleOfNode(node);
Expand All @@ -271,6 +281,7 @@ export function touchend(node, xy) {
* @param {?{
* emulateTouch: boolean
* }=} options Optional. Configure the emulation fidelity of the mouse events.
* @return {undefined}
*/
export function downAndUp(target, callback, options) {
if (options && options.emulateTouch) {
Expand All @@ -294,6 +305,7 @@ export function downAndUp(target, callback, options) {
* @param {?{
* emulateTouch: boolean
* }=} options Optional. Configure the emulation fidelity of the mouse event.
* @return {undefined}
*/
export function tap(node, options) {
// Respect nodes that are disabled in the UI.
Expand Down Expand Up @@ -326,6 +338,7 @@ export function focus(target) {
* Blurs a node by firing a `blur` event. This event does not bubble.
*
* @param {!Element} target The node to fire the event on.
* @return {undefined}
*/
export function blur(target) {
Base.fire('blur', {}, {bubbles: false, node: target});
Expand All @@ -340,6 +353,7 @@ export function blur(target) {
* @param {(string|Array<string>)=} modifiers The key modifiers for the event.
* Accepted values are shift, ctrl, alt, meta.
* @param {string=} key The KeyboardEvent.key value for the event.
* @return {!Event}
*/
export function keyboardEventFor(type, keyCode, modifiers, key) {
const event = new CustomEvent(type, {
Expand Down Expand Up @@ -378,6 +392,7 @@ export function keyboardEventFor(type, keyCode, modifiers, key) {
* @param {(string|Array<string>)=} modifiers The key modifiers for the event.
* Accepted values are shift, ctrl, alt, meta.
* @param {string=} key The KeyboardEvent.key value for the event.
* @return {undefined}
*/
export function keyEventOn(target, type, keyCode, modifiers, key) {
target.dispatchEvent(keyboardEventFor(type, keyCode, modifiers, key));
Expand All @@ -392,6 +407,7 @@ export function keyEventOn(target, type, keyCode, modifiers, key) {
* @param {(string|Array<string>)=} modifiers The key modifiers for the event.
* Accepted values are shift, ctrl, alt, meta.
* @param {string=} key The KeyboardEvent.key value for the event.
* @return {undefined}
*/
export function keyDownOn(target, keyCode, modifiers, key) {
keyEventOn(target, 'keydown', keyCode, modifiers, key);
Expand All @@ -406,6 +422,7 @@ export function keyDownOn(target, keyCode, modifiers, key) {
* @param {(string|Array<string>)=} modifiers The key modifiers for the event.
* Accepted values are shift, ctrl, alt, meta.
* @param {string=} key The KeyboardEvent.key value for the event.
* @return {undefined}
*/
export function keyUpOn(target, keyCode, modifiers, key) {
keyEventOn(target, 'keyup', keyCode, modifiers, key);
Expand All @@ -420,6 +437,7 @@ export function keyUpOn(target, keyCode, modifiers, key) {
* @param {(string|Array<string>)=} modifiers The key modifiers for the event.
* Accepted values are shift, ctrl, alt, meta.
* @param {string=} key The KeyboardEvent.key value for the event.
* @return {undefined}
*/
export function pressAndReleaseKeyOn(target, keyCode, modifiers, key) {
keyDownOn(target, keyCode, modifiers, key);
Expand All @@ -433,6 +451,7 @@ export function pressAndReleaseKeyOn(target, keyCode, modifiers, key) {
* followed by an asynchronous `keyup` event on a specific node.
*
* @param {!Element} target The node to fire the event on.
* @return {undefined}
*/
export function pressEnter(target) {
pressAndReleaseKeyOn(target, 13);
Expand Down
5 changes: 3 additions & 2 deletions test-helpers.js
Original file line number Diff line number Diff line change
Expand Up @@ -62,9 +62,10 @@ export function fireEvent(type, props, node) {
* ...
* });
*
* @param {Function} condition The name of a Boolean function determining if the
* test should be run.
* @param {Function} condition A Boolean function determining if the test should
* be run.
* @param {Function} test The test to be run.
* @return {Function}
*/
export function skipUnless(condition, test) {
const isAsyncTest = !!test.length;
Expand Down

0 comments on commit 262ebf3

Please sign in to comment.