-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Move
parentBy
to traversing
namespace
- Loading branch information
Showing
4 changed files
with
38 additions
and
38 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
/* @flow */ | ||
|
||
import type { Predicate, Selector } from "../types"; | ||
|
||
import matches from "./matches"; | ||
import parent from "./parent"; | ||
|
||
function parentBy(element: Element, condition: Predicate | Selector): ?Element { | ||
const predicate = typeof condition === "string" | ||
? e => matches(e, condition) | ||
: condition; | ||
|
||
let current = parent(element); | ||
|
||
while (current) { | ||
if (predicate(current)) { | ||
return current; | ||
} | ||
|
||
current = parent(current); | ||
} | ||
|
||
return null; | ||
} | ||
|
||
export default parentBy; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters