piral-react
Version:
Plugin for integrating React 16+ components in Piral.
57 lines • 1.6 kB
JavaScript
import { __setFunctionName } from "tslib";
import { createElement, Component } from 'react';
import { anyPropType } from './mount';
function compareObjects(a, b) {
for (const i in a) {
if (!(i in b)) {
return false;
}
}
for (const i in b) {
if (!compare(a[i], b[i])) {
return false;
}
}
return true;
}
function compare(a, b) {
if (a !== b) {
const ta = typeof a;
const tb = typeof b;
if (ta === tb && ta === 'object' && a && b) {
return compareObjects(a, b);
}
return false;
}
return true;
}
export function createExtension(rootName) {
var _a;
const ReactExtension = (_a = class extends Component {
constructor() {
super(...arguments);
this.onRefChange = (element) => {
if (element) {
const { piral } = this.context;
element.innerHTML = '';
piral.renderHtmlExtension(element, this.props);
}
};
}
shouldComponentUpdate(nextProps) {
return !compare(this.props, nextProps);
}
render() {
return createElement(rootName, {
ref: this.onRefChange,
});
}
},
__setFunctionName(_a, "ReactExtension"),
_a.contextTypes = {
piral: anyPropType,
},
_a);
return ReactExtension;
}
//# sourceMappingURL=extension.js.map