Skip to content

Commit

Permalink
Move on to events namespace
Browse files Browse the repository at this point in the history
  • Loading branch information
demiazz committed May 4, 2017
1 parent 57736e3 commit a94acf0
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 14 deletions.
2 changes: 1 addition & 1 deletion spec/on.spec.js → spec/events/on.spec.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { on } from "../src";
import { on } from "../../src";

describe("on", () => {
let subject;
Expand Down
15 changes: 15 additions & 0 deletions src/events/on.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
/* @flow */

import type { EventType } from "../types";

function on(
element: Element,
eventType: EventType,
listener: EventListener
): () => void {
element.addEventListener(eventType, listener);

return () => element.removeEventListener(eventType, listener);
}

export default on;
15 changes: 2 additions & 13 deletions src/index.js
Original file line number Diff line number Diff line change
@@ -1,12 +1,13 @@
/* @flow */

import type { Selector } from "./types";
import type { EventType, Selector } from "./types";

import { html, body } from "./aliases";
import addClass from "./css/add-class";
import hasClass from "./css/has-class";
import removeClass from "./css/remove-class";
import toggleClass from "./css/toggle-class";
import on from "./events/on";
import query from "./queries/query";
import queryAll from "./queries/query-all";
import matches from "./traversing/matches";
Expand All @@ -21,8 +22,6 @@ type EventDetails = { [key: string]: mixed };

type EventListener = (event: Event) => mixed;

type EventType = string;

type PredicateFn = (element: Element) => boolean;

/* Dataset */
Expand Down Expand Up @@ -118,16 +117,6 @@ function remove(element: Element): boolean {

/* Events */

function on(
element: Element,
eventType: EventType,
listener: EventListener
): () => void {
element.addEventListener(eventType, listener);

return () => element.removeEventListener(eventType, listener);
}

function once(
element: Element,
eventType: EventType,
Expand Down
2 changes: 2 additions & 0 deletions src/types.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@ export type CSSClass = string;

export type Elements = Array<Element>;

export type EventType = string;

export type Predicate = (element: Element) => boolean;

export type Selector = string;

0 comments on commit a94acf0

Please sign in to comment.