Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- this.state = {
- scene: fromJS([
- {
- conditions: [
- "any",
- [
- ["custom-event", "MY_EVENT", 1],
- ["custom-event", "MY_EVENT", 2],
- ["any", [["custom-event", "MY-EVENT", 3]]]
- ]
- ],
- actions: [["custom-action", 1], ["custom-action", 2]]
- },
- {
- conditions: [
- "any",
- [
- ["custom-event", "MY_EVENT", 4],
- ["custom-event", "MY_EVENT", 5],
- ["any", [["custom-event", "MY-EVENT", 6]]]
- ]
- ],
- actions: [["custom-action", 3], ["custom-action", 4], ["custom-action", 5]]
- }
- ])
- };
- onChange(from: any, to: any) {
- const stateImmutable = this.state.scene;
- const source = from;
- const target = to;
- const sourceItem = stateImmutable.getIn(source);
- let changeTargetPos = target[target.length - 1];
- if (source.length > target.length) {
- changeTargetPos = target.length - 1;
- } else if (source.length < target.length) {
- changeTargetPos = source.length - 1;
- }
- let newTarget = target;
- if (target[changeTargetPos] > source[changeTargetPos]) {
- newTarget[changeTargetPos] = newTarget[changeTargetPos] - 1;
- }
- const newState = stateImmutable.removeIn(source);
- const n = newState.updateIn(newTarget.slice(0, -1), (list: any) => {
- return list.insert(newTarget[newTarget.length - 1], sourceItem);
- });
- this.setState({ scene: n });
- }
- from: [1, "conditions", 1, 1, 1, 0] to: [1, "conditions", 1, 1, 1, 1]
Add Comment
Please, Sign In to add comment