commit
b7c2eb99b2
1 changed files with 1 additions and 14 deletions
|
@ -9,9 +9,6 @@ const CLASS_NAME_ATTR = 'data-react-class';
|
||||||
// example: `data-react-props="{\"item\": { \"id\": 1, \"name\": \"My Item\"} }"`
|
// example: `data-react-props="{\"item\": { \"id\": 1, \"name\": \"My Item\"} }"`
|
||||||
const PROPS_ATTR = 'data-react-props';
|
const PROPS_ATTR = 'data-react-props';
|
||||||
|
|
||||||
// A unique identifier to identify a node
|
|
||||||
const CACHE_ID_ATTR = 'data-react-cache-id';
|
|
||||||
|
|
||||||
const CLASS_NAME_SELECTOR = `[${CLASS_NAME_ATTR}]`;
|
const CLASS_NAME_SELECTOR = `[${CLASS_NAME_ATTR}]`;
|
||||||
|
|
||||||
// helper method for the mount and unmount methods to find the
|
// helper method for the mount and unmount methods to find the
|
||||||
|
@ -40,7 +37,6 @@ function getSelector(searchSelector) {
|
||||||
}
|
}
|
||||||
|
|
||||||
class ReactComponentRegistry {
|
class ReactComponentRegistry {
|
||||||
#cache = {};
|
|
||||||
#components;
|
#components;
|
||||||
|
|
||||||
constructor(components) {
|
constructor(components) {
|
||||||
|
@ -59,7 +55,6 @@ class ReactComponentRegistry {
|
||||||
const ComponentClass = this.getConstructor(className);
|
const ComponentClass = this.getConstructor(className);
|
||||||
const propsJson = node.getAttribute(PROPS_ATTR);
|
const propsJson = node.getAttribute(PROPS_ATTR);
|
||||||
const props = propsJson && JSON.parse(propsJson);
|
const props = propsJson && JSON.parse(propsJson);
|
||||||
const cacheId = node.getAttribute(CACHE_ID_ATTR);
|
|
||||||
|
|
||||||
if (!ComponentClass) {
|
if (!ComponentClass) {
|
||||||
const message = `Cannot find component: "${className}"`;
|
const message = `Cannot find component: "${className}"`;
|
||||||
|
@ -73,15 +68,7 @@ class ReactComponentRegistry {
|
||||||
`${message}. Make sure your component is available to render.`
|
`${message}. Make sure your component is available to render.`
|
||||||
);
|
);
|
||||||
} else {
|
} else {
|
||||||
let component = this.#cache[cacheId];
|
render(createElement(ComponentClass, props), node);
|
||||||
if (!component) {
|
|
||||||
this.#cache[cacheId] = component = createElement(
|
|
||||||
ComponentClass,
|
|
||||||
props
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
render(component, node);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Reference in a new issue