Skip to content

Commit

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

describe("matches", () => {
afterEach(clearFixtures);
Expand Down
24 changes: 1 addition & 23 deletions src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import type { Elements, Selector } from "./types";
import { html, body } from "./aliases";
import query from "./queries/query";
import queryAll from "./queries/query-all";
import matches from "./traversing/matches";

/* Types */

Expand All @@ -18,29 +19,6 @@ type EventType = string;

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

/* Queries */

type MatchesFn = (selector: Selector) => boolean;

function getMatchesFn(): MatchesFn {
const element = (document.createElement("div"): any);

return (
element.matches ||
element.matchesSelector ||
element.msMatchesSelector ||
element.mozMatchesSelector ||
element.webkitMatchesSelector ||
element.oMatchesSelector
);
}

const matchesFn: MatchesFn = getMatchesFn();

function matches(element: Element, selector: Selector): boolean {
return matchesFn.call(element, selector);
}

/* Classes */

function hasClass(element: Element, cssClass: CSSClass): boolean {
Expand Down
26 changes: 26 additions & 0 deletions src/traversing/matches.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
/* @flow */

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

type Matches = (selector: Selector) => boolean;

function getMatchesFn(): Matches {
const element = (document.createElement("div"): any);

return (
element.matches ||
element.matchesSelector ||
element.msMatchesSelector ||
element.mozMatchesSelector ||
element.webkitMatchesSelector ||
element.oMatchesSelector
);
}

const matchesFn: Matches = getMatchesFn();

function matches(element: Element, selector: Selector): boolean {
return matchesFn.call(element, selector);
}

export default matches;

0 comments on commit b936ccd

Please sign in to comment.