@@ -12,114 +12,114 @@ import {defaultState} from './store/state/index.js'
12
12
13
13
let redoMixin = {
14
14
data () {
15
- return {
16
- // banana:[],
17
- doneAction: [],
18
- undoneAction: [],
19
- isTimetraveling: false ,
20
- initialState: {}
21
- }
22
- },
23
-
24
- created (){
25
-
26
- this .$store .subscribeAction ((action ,state )=> {
27
- // console.log("We are saving this action!", action)
28
- if (typeof action .payload === " object" ){
29
- // console.log("We saved the world with a deepclone!", action.payload === cloneDeep)
30
- action .payload = cloneDeep (action .payload )
31
- }
32
- this .doneAction .push (action)
33
- // console.log('this is the action we are logging',action)
34
- // console.log('this is in our redo queue', this.undoneAction[this.undoneAction.length-1])
35
- // console.log("Are these equal to each other?", action == this.undoneAction[this.undoneAction.length-1])
36
- if (! this .isTimetraveling ){
37
- if (this .undoneAction [this .undoneAction .length - 1 ]){
38
- if (action .type == this .undoneAction [this .undoneAction .length - 1 ].type &&
39
- deepEqual (action .payload ,this .undoneAction [this .undoneAction .length - 1 ].payload )){
40
- this .undoneAction .pop ()
41
- }
42
- else {
43
- this .undoneAction = []
44
- }
45
- }
46
- }
47
- })
48
- // this.blankState = cloneDeep(this.$store)
49
- },
15
+ return {
16
+ // banana:[],
17
+ doneAction: [],
18
+ undoneAction: [],
19
+ isTimetraveling: false ,
20
+ initialState: {}
21
+ }
22
+ },
23
+
24
+ created () {
50
25
51
- mounted (){
52
- window .addEventListener (" keydown" , event => {
53
- if (event .ctrlKey && event .key === " z" ) {
54
- event .preventDefault ()
55
- this .undo ()
26
+ this .$store .subscribeAction ((action , state ) => {
27
+ // console.log("We are saving this action!", action)
28
+ if (typeof action .payload === " object" ) {
29
+ // console.log("We saved the world with a deepclone!", action.payload === cloneDeep)
30
+ action .payload = cloneDeep (action .payload )
31
+ }
32
+ this .doneAction .push (action)
33
+ // console.log('this is the action we are logging',action)
34
+ // console.log('this is in our redo queue', this.undoneAction[this.undoneAction.length-1])
35
+ // console.log("Are these equal to each other?", action == this.undoneAction[this.undoneAction.length-1])
36
+ if (! this .isTimetraveling ) {
37
+ if (this .undoneAction [this .undoneAction .length - 1 ]) {
38
+ if (action .type == this .undoneAction [this .undoneAction .length - 1 ].type &&
39
+ deepEqual (action .payload ,this .undoneAction [this .undoneAction .length - 1 ].payload )) {
40
+ this .undoneAction .pop ()
56
41
}
57
- });
58
- window .addEventListener (" keydown" , event => {
59
- if (event .ctrlKey && event .key === " y" ) {
60
- event .preventDefault ()
61
- this .redo ()
42
+ else {
43
+ this .undoneAction = []
62
44
}
63
- });
64
- // console.log("do we want this? or this.$store.state?", this.$store.state)
65
- this .initialState = defaultState (this .$store .state )
45
+ }
46
+ }
47
+ })
48
+ // this.blankState = cloneDeep(this.$store)
49
+ },
66
50
67
- },
51
+ mounted (){
52
+ window .addEventListener (" keydown" , event => {
53
+ if (event .ctrlKey && event .key === " z" ) {
54
+ event .preventDefault ()
55
+ this .undo ()
56
+ }
57
+ });
58
+ window .addEventListener (" keydown" , event => {
59
+ if (event .ctrlKey && event .key === " y" ) {
60
+ event .preventDefault ()
61
+ this .redo ()
62
+ }
63
+ });
64
+ // console.log("do we want this? or this.$store.state?", this.$store.state)
65
+ this .initialState = defaultState (this .$store .state )
68
66
69
- methods: {
70
- undo : function () {
71
- // do {
72
- // console.log("How far back?")
67
+ },
73
68
74
- this .isTimetraveling = true ;
69
+ methods: {
70
+ undo : function () {
71
+ // do {
72
+ // console.log("How far back?")
75
73
76
- let undone = this .doneAction .pop ()
77
-
78
- if (undone !== undefined ){
79
- this .undoneAction .push (undone)
80
- if (undone .type === " setActiveComponent" ){
81
- console .log (" We did something useless!" )
82
- do {
83
- this .undoneAction .push (this .doneAction .pop ())
84
- }
85
- while (this .doneAction [this .doneAction .length - 1 ] &&
86
- (this .doneAction [this .doneAction .length - 1 ].type === " setActiveComponent" ))
87
- }
88
- }
74
+ this .isTimetraveling = true ;
89
75
90
- // while (this.doneAction[this.doneAction.length-1] &&
91
- // (this.doneAction[this.doneAction.length - 1].type === "setActiveComponent" ||
92
- // this.doneAction[this.doneAction.length - 1].type === "updateComponentPosition" ))
93
- let payload = {
94
- initialState: this .initialState ,
95
- store: this .$store
96
- }
97
- this .$store .commit (" EMPTY_STATE" ,payload)
98
- console .log (this .$store )
99
- this .doneAction .forEach (action => {
100
- console .log (" In the loop" ,this .$store )
101
- // this.$store.commit(`${mutation.type}`, mutation.payload);
102
- this .$store .dispatch (action .type , cloneDeep (action .payload ));
103
- this .doneAction .pop ();
104
- });
105
- this .isTimetraveling = false ;
76
+ let undone = this .doneAction .pop ()
106
77
107
- },
108
- redo : function () {
109
-
110
- let action = this .undoneAction .pop ()
111
- this .isTimetraveling = true ;
112
- if (action){
113
- this .$store .dispatch (action .type , cloneDeep (action .payload ))
114
- }
115
- this .isTimetraveling = false ;
116
- if (action && (action .type === " setActiveComponent" )){
117
- console .log (" WE GOTTA DO MORE" )
118
- this .redo ();
119
- }
78
+ if (undone !== undefined ) {
79
+ this .undoneAction .push (undone)
80
+ if (undone .type === " setActiveComponent" ) {
81
+ console .log (" We did something useless!" )
82
+ do {
83
+ this .undoneAction .push (this .doneAction .pop ())
120
84
}
85
+ while (this .doneAction [this .doneAction .length - 1 ] &&
86
+ (this .doneAction [this .doneAction .length - 1 ].type === " setActiveComponent" ))
87
+ }
88
+ }
121
89
90
+ // while (this.doneAction[this.doneAction.length-1] &&
91
+ // (this.doneAction[this.doneAction.length - 1].type === "setActiveComponent" ||
92
+ // this.doneAction[this.doneAction.length - 1].type === "updateComponentPosition" ))
93
+ let payload = {
94
+ initialState: this .initialState ,
95
+ store: this .$store
122
96
}
97
+ this .$store .commit (" EMPTY_STATE" ,payload)
98
+ console .log (this .$store )
99
+ this .doneAction .forEach (action => {
100
+ console .log (" In the loop" ,this .$store )
101
+ // this.$store.commit(`${mutation.type}`, mutation.payload);
102
+ this .$store .dispatch (action .type , cloneDeep (action .payload ));
103
+ this .doneAction .pop ();
104
+ });
105
+ this .isTimetraveling = false ;
106
+
107
+ },
108
+ redo : function () {
109
+
110
+ let action = this .undoneAction .pop ()
111
+ this .isTimetraveling = true ;
112
+ if (action) {
113
+ this .$store .dispatch (action .type , cloneDeep (action .payload ))
114
+ }
115
+ this .isTimetraveling = false ;
116
+ if (action && (action .type === " setActiveComponent" )) {
117
+ console .log (" WE GOTTA DO MORE" )
118
+ this .redo ();
119
+ }
120
+ }
121
+
122
+ }
123
123
}
124
124
125
125
0 commit comments