import * as React from "react"; import { Observable } from "babylonjs"; import { PropertyChangedEvent } from "components/propertyChangedEvent"; interface ITextInputLineComponentProps { label: string, target: any, propertyName: string, onPropertyChangedObservable?: Observable } export class TextInputLineComponent extends React.Component { private _localChange = false; constructor(props: ITextInputLineComponentProps) { super(props); this.state = { value: this.props.target[this.props.propertyName] || "" } } shouldComponentUpdate(nextProps: ITextInputLineComponentProps, nextState: { value: string }) { if (this._localChange) { this._localChange = false; return true; } const newValue = nextProps.target[nextProps.propertyName]; if (newValue !== nextState.value) { nextState.value = newValue || ""; return true; } return false; } raiseOnPropertyChanged(newValue: string, previousValue: string) { if (!this.props.onPropertyChangedObservable) { return; } this.props.onPropertyChangedObservable.notifyObservers({ object: this.props.target, property: this.props.propertyName, value: newValue, initialValue: previousValue }); } updateValue(value: string) { this._localChange = true; const store = this.props.target[this.props.propertyName]; this.setState({ value: value }); this.raiseOnPropertyChanged(value, store); this.props.target[this.props.propertyName] = value; } render() { return (
{this.props.label}
this.updateValue(evt.target.value)} />
); } }