diff --git a/spec/remove.spec.js b/spec/manipulation/remove.spec.js similarity index 80% rename from spec/remove.spec.js rename to spec/manipulation/remove.spec.js index 59cc3c1..9e372a4 100644 --- a/spec/remove.spec.js +++ b/spec/manipulation/remove.spec.js @@ -1,12 +1,8 @@ -import { remove } from "../src"; +import { remove } from "../../src"; describe("remove", () => { it("removes element if attached to DOM", () => { - useFixture( - ` -
- ` - ); + useFixture(`
`); const subject = document.querySelector(".root"); diff --git a/src/index.js b/src/index.js index b822c6e..ed6c6a9 100644 --- a/src/index.js +++ b/src/index.js @@ -11,6 +11,7 @@ import delegate from "./events/delegate"; import dispatch from "./events/dispatch"; import on from "./events/on"; import once from "./events/once"; +import remove from "./manipulation/remove"; import query from "./queries/query"; import queryAll from "./queries/query-all"; import matches from "./traversing/matches"; @@ -100,20 +101,6 @@ function closest( return parentBy(element, condition); } -/* Manipulate */ - -function remove(element: Element): boolean { - const parentElement = parent(element); - - if (parentElement) { - parentElement.removeChild(element); - - return true; - } - - return false; -} - /* Exports */ export { diff --git a/src/manipulation/remove.js b/src/manipulation/remove.js new file mode 100644 index 0000000..0dc0f20 --- /dev/null +++ b/src/manipulation/remove.js @@ -0,0 +1,17 @@ +/* @flow */ + +import parent from "../traversing/parent"; + +function remove(element: Element): boolean { + const parentElement = parent(element); + + if (parentElement) { + parentElement.removeChild(element); + + return true; + } + + return false; +} + +export default remove;