-
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.
BREAKING: createHook now only returns a proxy. Closes #10 Static siblings is also now retained. Closes #24
- Loading branch information
1 parent
e766232
commit 558fc15
Showing
5 changed files
with
169 additions
and
118 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
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,47 @@ | ||
import { compose, resolve } from './general'; | ||
import { uid } from './id'; | ||
import { getKey, setMetadata } from './meta'; | ||
|
||
/** | ||
* Append a callback to the hook | ||
* @param {any} hook | ||
* @param {Function} callback | ||
* @returns {any} | ||
*/ | ||
export const addTrap = (hook, callback) => { | ||
const previousTrap = hook.data.trap; | ||
hook.data.trap = compose((value) => resolve(value, previousTrap), callback); | ||
|
||
return hook; | ||
}; | ||
|
||
/** | ||
* Get the index of bounding comment markers | ||
* @param {string} id | ||
* @param {Node[]} nodes | ||
* @returns {[number, number]} | ||
*/ | ||
export const getBoundary = (id, nodes) => { | ||
const start = nodes.findIndex((n) => getKey(n) === `start_${id}`); | ||
const end = nodes.findIndex((n) => getKey(n) === `end_${id}`); | ||
|
||
return [start + 1, end]; | ||
}; | ||
|
||
/** | ||
* Create marker comments to easily mark the start and end | ||
* of where the hook is passed in the body | ||
* @returns {[Comment,Comment,string]} | ||
*/ | ||
export const createMarkers = () => { | ||
const id = uid(); | ||
|
||
// Use comments to easily mark the start and end | ||
// of where we should insert our children | ||
const head = document.createComment('MARKER'); | ||
const tail = document.createComment('END'); | ||
setMetadata(head, 'key', `start_${id}`); | ||
setMetadata(tail, 'key', `end_${id}`); | ||
|
||
return [head, tail, id]; | ||
}; |
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