@@ -5,8 +5,8 @@ import { moveRegion } from "../../ImageCanvas/region-tools.js"
55import  {  getIn ,  setIn ,  updateIn  }  from  "seamless-immutable" 
66import  moment  from  "moment" 
77import  isEqual  from  "lodash/isEqual" 
8- import  merge  from  "lodash/fp/merge" 
98import  getActiveImage  from  "./get-active-image" 
9+ import  {  saveToHistory  }  from  "./history-handler.js" 
1010
1111const  getRandomId  =  ( )  => 
1212 Math . random ( ) 
@@ -24,12 +24,6 @@ const getRandomColor = () => {
2424 return  `hsl(${ h }  ,${ s }  %,${ l }  %)` 
2525} 
2626
27- const  typesToSaveWithHistory  =  { 
28-  BEGIN_BOX_TRANSFORM : "Transform/Move Box" , 
29-  BEGIN_MOVE_POINT : "Move Point" , 
30-  DELETE_REGION : "Delete Region" 
31- } 
32- 
3327export  default  ( state : MainLayoutState ,  action : Action )  =>  { 
3428 // Throttle certain actions 
3529 if  ( action . type  ===  "MOUSE_MOVE" )  { 
@@ -63,12 +57,10 @@ export default (state: MainLayoutState, action: Action) => {
6357 const  [ region ,  regionIndex ]  =  getRegion ( regionId ) 
6458 if  ( ! region )  return  state 
6559 if  ( obj  !==  null )  { 
66-  return  updateIn ( 
67-  state , 
68-  [ ...pathToActiveImage ,  "regions" ,  regionIndex ] , 
69-  merge , 
70-  obj 
71-  ) 
60+  return  setIn ( state ,  [ ...pathToActiveImage ,  "regions" ,  regionIndex ] ,  { 
61+  ...region , 
62+  ...obj 
63+  } ) 
7264 }  else  { 
7365 // delete region 
7466 const  regions  =  activeImage . regions 
@@ -91,24 +83,6 @@ export default (state: MainLayoutState, action: Action) => {
9183 ) 
9284 } 
9385
94-  const  saveToHistory  =  ( state : MainLayoutState ,  name : string )  => 
95-  updateIn ( state ,  [ "history" ] ,  h  => 
96-  [ 
97-  { 
98-  time : moment ( ) . toDate ( ) , 
99-  state, 
100-  name
101-  } 
102-  ] . concat ( ( h  ||  [ ] ) . slice ( 0 ,  9 ) ) 
103-  ) 
104- 
105-  if  ( Object . keys ( typesToSaveWithHistory ) . includes ( action . type ) )  { 
106-  state  =  saveToHistory ( 
107-  state , 
108-  typesToSaveWithHistory [ action . type ]  ||  action . type 
109-  ) 
110-  } 
111- 
11286 const  closeEditors  =  ( state : MainLayoutState )  =>  { 
11387 if  ( currentImageIndex  ===  null )  return  state 
11488 return  setIn ( 
@@ -153,19 +127,13 @@ export default (state: MainLayoutState, action: Action) => {
153127 action . region 
154128 ) 
155129 } 
156-  case  "RESTORE_HISTORY ": { 
157-  if  ( state . history . length  >  0 )  { 
158-  return  state . history [ 0 ] . state 
159-  } 
160-  return  state 
161-  } 
162130 case  "CHANGE_IMAGE ": { 
163131 if  ( ! activeImage )  return  state 
164132 const  {  delta  }  =  action 
165133 for  ( const  key  of  Object . keys ( delta ) )  { 
166134 if  ( key  ===  "cls" )  saveToHistory ( state ,  "Change Image Class" ) 
167135 if  ( key  ===  "tags" )  saveToHistory ( state ,  "Change Image Tags" ) 
168-  state  =  setIn ( state ,  [ ...pageToActiveImage ,  key ] ,  delta [ key ] ) 
136+  state  =  setIn ( state ,  [ ...pathToActiveImage ,  key ] ,  delta [ key ] ) 
169137 } 
170138 return  state 
171139 } 
@@ -406,7 +374,7 @@ export default (state: MainLayoutState, action: Action) => {
406374 case  "DRAW_POLYGON ": { 
407375 const  [ polygon ,  regionIndex ]  =  getRegion ( state . mode . regionId ) 
408376 if  ( ! polygon )  break 
409-  state   =  setIn ( 
377+  return  setIn ( 
410378 state , 
411379 [ ...pathToActiveImage ,  "regions" ,  regionIndex ] , 
412380 {  ...polygon ,  points : polygon . points . concat ( [ [ x ,  y ] ] )  } 
0 commit comments