Skip to content

Commit

Permalink
Move parents to traversing namespace
Browse files Browse the repository at this point in the history
  • Loading branch information
demiazz committed May 4, 2017
1 parent 880a3eb commit d1352ec
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 19 deletions.
8 changes: 3 additions & 5 deletions spec/parents.spec.js → spec/traversing/parents.spec.js
Original file line number Diff line number Diff line change
@@ -1,14 +1,12 @@
import { parents } from "../src";
import { parents } from "../../src";

describe("parents", () => {
it("returns all parents", () => {
useFixture(
`
useFixture(`
<div class="parent">
<div class="root"></div>
</div>
`
);
`);

const subject = document.querySelector(".root");

Expand Down
15 changes: 1 addition & 14 deletions src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import queryAll from "./queries/query-all";
import matches from "./traversing/matches";
import parent from "./traversing/parent";
import parentBy from "./traversing/parent-by";
import parents from "./traversing/parents";

/* Types */

Expand Down Expand Up @@ -98,20 +99,6 @@ function dataset(element: HTMLElement): Dataset {
* Traverse
*/

function parents(element: Element): Elements {
const result = [];

let current = parent(element);

while (current) {
result.push(current);

current = parent(current);
}

return result;
}

function parentsBy(
element: Element,
condition: Selector | PredicateFn
Expand Down
21 changes: 21 additions & 0 deletions src/traversing/parents.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
/* @flow */

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

import parent from "./parent";

function parents(element: Element): Elements {
const result = [];

let current = parent(element);

while (current) {
result.push(current);

current = parent(current);
}

return result;
}

export default parents;

0 comments on commit d1352ec

Please sign in to comment.