Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
componentWillReceiveProps(newProps) {
if (newProps.ast) {
console.log('newProps.ast',newProps.ast)
//this.setState({ast: newProps.ast})
return;
}
if (newProps.markup) {
const hash = hashCode(newProps.markup);
if (hash !== this.state.hash) {
this.setState({ previousAST: this.state.ast });
compile(newProps.markup, newProps.compilerOptions)
.then((ast) => {
this.setState({ previousAST: ast, ast, hash, error: null });
})
.catch(this.componentDidCatch.bind(this));
}
}
}
componentWillReceiveProps(newProps) {
if (newProps.ast) {
return;
}
const hash = hashCode(newProps.markup);
if (hash !== this.state.hash) {
this.setState({ previousAST: this.state.ast });
compile(newProps.markup, newProps.compilerOptions)
.then(ast => {
this.setState({ previousAST: ast, ast, hash, error: null });
})
.catch(this.componentDidCatch.bind(this));
}
}
handleChange(value) {
const hash = hashCode(value.trim());
if (hash === this.state.hashCode) {
return;
}
try {
const ast = compile(value);
this.setState({
idyllHash: hash,
idyllMarkup: value,
ast: ast,
error: null
})
} catch(e) {
this.setState({
error: e.message
})
}
}
constructor(props) {
super(props);
this.state = {
idyllMarkup: initialValue,
idyllHash: '',
error: null,
ast: compile(initialValue)
}
this.handleChange = this.handleChange.bind(this);
}
componentDidMount() {
if (!this.props.ast && this.props.markup) {
compile(this.props.markup, this.props.compilerOptions).then(ast => {
this.setState({ ast, hash: hashCode(this.props.markup), error: null });
});
}
}
componentDidMount() {
if (!this.props.ast && this.props.markup) {
compile(this.props.markup, this.props.compilerOptions)
.then((ast) => {
this.setState({ ast, hash: hashCode(this.props.markup), error: null });
})
}
}