piral-core
Version:
The core library for creating a Piral instance.
46 lines • 1.54 kB
JavaScript
import * as React from 'react';
import { isfunc } from 'piral-base';
export class ForeignComponentContainer extends React.Component {
constructor() {
super(...arguments);
this.locals = {};
this.setNode = (node) => {
this.current = node;
};
}
componentDidMount() {
const { current } = this;
const { $component, $context, innerProps } = this.props;
const { mount } = $component;
if (current && isfunc(mount)) {
mount(current, innerProps, $context, this.locals);
}
this.previous = current;
}
componentDidUpdate() {
const { current, previous } = this;
const { $component, $context, innerProps } = this.props;
const { update } = $component;
if (current !== previous) {
previous && this.componentWillUnmount();
current && this.componentDidMount();
}
else if (isfunc(update)) {
update(current, innerProps, $context, this.locals);
}
}
componentWillUnmount() {
const { previous } = this;
const { $component } = this.props;
const { unmount } = $component;
if (previous && isfunc(unmount)) {
unmount(previous, this.locals);
}
this.previous = undefined;
}
render() {
const { $portalId } = this.props;
return React.createElement("piral-portal", { pid: $portalId, ref: this.setNode });
}
}
//# sourceMappingURL=ForeignComponentContainer.js.map