Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
try {
component = React.render(React.createElement(
Component, props, fixture.children),
_container);
} catch (e) {
throw new Error(
`The component threw an exception while rendering:\n ${e.message}`);
}
if (fixture.state) {
// Injecting state will trigger a new render cycle and we only care about
// the calls caused by the last render
sandbox.reset();
ComponentTree.injectState(component, fixture.state);
}
return component;
}
componentDidMount() {
$(window).on('unload', this.onUnload);
// Unload previous state from local storage if present, otherwise
// a blank Flatris instance will be rendered
var prevState = localStorage.getItem('flatrisState');
if (prevState) {
ComponentTree.injectState(this.refs.flatrisStatePreview,
JSON.parse(prevState));
}
}
onComponentRef(componentRef) {
const {
fixture,
onComponentRef,
disableLocalState,
} = this.props;
// Ref callbacks are also called on unmount with null value
if (componentRef && !disableLocalState) {
// Load initial state right after component renders
const fixtureState = fixture[fixtureKey];
if (fixtureState) {
ReactComponentTree.injectState(componentRef, fixtureState);
this.scheduleStateUpdate();
} else {
const initialState = this.getStateTree(componentRef);
// No need to poll for state changes if entire component tree is stateless
if (initialState) {
this.updateState(initialState);
}
}
}
if (!componentRef) {
clearTimeout(this.timeoutId);
}
// Bubble up component ref
onComponentRef(this.componentRef = componentRef);
_injectPreviewChildState: function() {
var state = this.state.fixtureContents.state;
if (!_.isEmpty(state)) {
ComponentTree.injectState(this.refs.preview, _.cloneDeep(state));
}
},