main
Last change
on this file was d24f17c, checked in by Aleksandar Panovski <apano77@…>, 15 months ago |
Initial commit
|
-
Property mode
set to
100644
|
File size:
888 bytes
|
Line | |
---|
1 | import { dispatchPlugins } from "./plugins/utils/index.mjs";
|
---|
2 | import { getNodeType } from "../traversal/visitor.mjs";
|
---|
3 | import createToolbox from "./toolbox.mjs";
|
---|
4 | const refract = (value, {
|
---|
5 | Type,
|
---|
6 | plugins = []
|
---|
7 | }) => {
|
---|
8 | /**
|
---|
9 | * This is where values gets refracted into generic ApiDOM.
|
---|
10 | * We don't allow consumers to hook into this translation.
|
---|
11 | * Though we allow consumers to define their onw plugins on already transformed ApiDOM.
|
---|
12 | */
|
---|
13 | const element = new Type(value);
|
---|
14 |
|
---|
15 | /**
|
---|
16 | * Run plugins only when necessary.
|
---|
17 | * Running plugins visitors means extra single traversal === performance hit.
|
---|
18 | */
|
---|
19 | return dispatchPlugins(element, plugins, {
|
---|
20 | toolboxCreator: createToolbox,
|
---|
21 | visitorOptions: {
|
---|
22 | nodeTypeGetter: getNodeType
|
---|
23 | }
|
---|
24 | });
|
---|
25 | };
|
---|
26 | export const createRefractor = Type => (value, options = {}) => refract(value, {
|
---|
27 | ...options,
|
---|
28 | Type
|
---|
29 | });
|
---|
30 | export default refract; |
---|
Note:
See
TracBrowser
for help on using the repository browser.