Guest User

Untitled

a guest
Mar 22nd, 2018
96
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.44 KB | None | 0 0
  1. this.state = {
  2. scene: fromJS([
  3. {
  4. conditions: [
  5. "any",
  6. [
  7. ["custom-event", "MY_EVENT", 1],
  8. ["custom-event", "MY_EVENT", 2],
  9. ["any", [["custom-event", "MY-EVENT", 3]]]
  10. ]
  11. ],
  12. actions: [["custom-action", 1], ["custom-action", 2]]
  13. },
  14. {
  15. conditions: [
  16. "any",
  17. [
  18. ["custom-event", "MY_EVENT", 4],
  19. ["custom-event", "MY_EVENT", 5],
  20. ["any", [["custom-event", "MY-EVENT", 6]]]
  21. ]
  22. ],
  23. actions: [["custom-action", 3], ["custom-action", 4], ["custom-action", 5]]
  24. }
  25. ])
  26. };
  27.  
  28. onChange(from: any, to: any) {
  29. const stateImmutable = this.state.scene;
  30. const source = from;
  31. const target = to;
  32. const sourceItem = stateImmutable.getIn(source);
  33. let changeTargetPos = target[target.length - 1];
  34. if (source.length > target.length) {
  35. changeTargetPos = target.length - 1;
  36. } else if (source.length < target.length) {
  37. changeTargetPos = source.length - 1;
  38. }
  39.  
  40. let newTarget = target;
  41.  
  42. if (target[changeTargetPos] > source[changeTargetPos]) {
  43. newTarget[changeTargetPos] = newTarget[changeTargetPos] - 1;
  44. }
  45.  
  46. const newState = stateImmutable.removeIn(source);
  47.  
  48. const n = newState.updateIn(newTarget.slice(0, -1), (list: any) => {
  49. return list.insert(newTarget[newTarget.length - 1], sourceItem);
  50. });
  51.  
  52. this.setState({ scene: n });
  53. }
  54.  
  55. from: [1, "conditions", 1, 1, 1, 0] to: [1, "conditions", 1, 1, 1, 1]
Add Comment
Please, Sign In to add comment