UNPKG

@gravity-ui/graph

Version:

Modern graph editor component

122 lines (121 loc) 3.09 kB
import { CoreComponent } from "./CoreComponent"; import { assign } from "./utils"; export class Component extends CoreComponent { constructor(props, parent) { super(props, parent); this.firstIterate = true; this.firstRender = true; this.firstUpdateChildren = true; this.shouldRender = true; this.shouldUpdateChildren = true; this.shouldRenderChildren = true; this.__data = { nextProps: undefined, nextState: undefined, }; this.state = {}; } willMount() { // noop } setContext(context) { this.shouldRenderChildren = true; this.shouldUpdateChildren = true; super.setContext(context); } setProps(props) { if (props === undefined) return; const data = this.__data; if (data.nextProps === undefined) { data.nextProps = assign(assign({}, this.props), props); this.performRender(); } else { assign(data.nextProps, props); } } setState(state) { const data = this.__data; if (data.nextState === undefined) { data.nextState = assign(assign({}, this.state), state); this.performRender(); } else { assign(data.nextState, state); } } propsChanged(_nextProps) { // noop } stateChanged(_nextState) { // noop } checkData() { const data = this.__data; if (data.nextProps !== undefined) { this.propsChanged(data.nextProps); assign(this.props, data.nextProps); data.nextProps = undefined; } if (data.nextState !== undefined) { this.stateChanged(data.nextState); assign(this.state, data.nextState); data.nextState = undefined; } } willRender() { // noop } didRender() { // noop } renderLifeCycle() { this.willRender(); this.render(); this.didRender(); this.firstRender = false; } willUpdateChildren() { // noop } didUpdateChildren() { // noop } childrenLifeCycle() { this.willUpdateChildren(); this.__updateChildren(); this.didUpdateChildren(); this.firstUpdateChildren = false; } willIterate() { if (this.firstIterate) { this.willMount(); } // noop } didIterate() { // noop } willNotRender() { // noop } iterate() { super.iterate(); this.checkData(); this.willIterate(); if (this.shouldRender) { this.renderLifeCycle(); } else { this.willNotRender(); } if (this.shouldUpdateChildren) { this.shouldUpdateChildren = false; this.childrenLifeCycle(); } this.didIterate(); this.firstIterate = false; return this.shouldRenderChildren; } }