fix inserting/deleting children

Summary: Inserting or deleting nodes threw an error, due to some changes I made earlier. This fixes the error.

Reviewed By: emilsjolander

Differential Revision: D6975950

fbshipit-source-id: d04df08260ab8ab248726809329e69f4d264decd
This commit is contained in:
Daniel Büchele
2018-02-13 06:13:27 -08:00
committed by Facebook Github Bot
parent a3144150e0
commit 9c877a621e

View File

@@ -146,9 +146,8 @@ export default class Playground extends Component<Props, State> {
const {selectedNodePath, layoutDefinition} = this.state; const {selectedNodePath, layoutDefinition} = this.state;
if (selectedNodePath) { if (selectedNodePath) {
const index = selectedNodePath.pop(); const index = selectedNodePath.pop();
const updatedChildren = layoutDefinition const path = getPath(selectedNodePath).concat('children');
.getIn(getPath(selectedNodePath)) const updatedChildren = layoutDefinition.getIn(path).delete(index);
.delete(index);
this.modifyAtPath(path, updatedChildren); this.modifyAtPath(path, updatedChildren);
this.setState({selectedNodePath: null}); this.setState({selectedNodePath: null});
} }
@@ -157,9 +156,8 @@ export default class Playground extends Component<Props, State> {
onAdd = () => { onAdd = () => {
const {selectedNodePath, layoutDefinition} = this.state; const {selectedNodePath, layoutDefinition} = this.state;
if (selectedNodePath) { if (selectedNodePath) {
const updatedChildren = layoutDefinition const path = getPath(selectedNodePath).concat('children');
.getIn(getPath(selectedNodePath)) const updatedChildren = layoutDefinition.getIn(path).push(LayoutRecord());
.push(LayoutRecord());
this.modifyAtPath( this.modifyAtPath(
path, path,
updatedChildren, updatedChildren,
@@ -173,7 +171,6 @@ export default class Playground extends Component<Props, State> {
value: any, value: any,
selectedNodePath?: ?Array<number> = this.state.selectedNodePath, selectedNodePath?: ?Array<number> = this.state.selectedNodePath,
) { ) {
console.log(setIn);
// $FlowFixMe // $FlowFixMe
const layoutDefinition = setIn(this.state.layoutDefinition, path, value); const layoutDefinition = setIn(this.state.layoutDefinition, path, value);
this.setState({ this.setState({