8
8
import { SET_ACTIVE_COMPONENT } from ' ./store/types'
9
9
const deepEqual = require (' lodash.isequal' )
10
10
const cloneDeep = require (' lodash.clonedeep' )
11
- import {defaultState } from ' ./store/state/index.js'
11
+ import { defaultState } from ' ./store/state/index.js'
12
12
13
13
let redoMixin = {
14
- data () {
14
+ data () {
15
15
return {
16
16
// banana:[],
17
- doneAction: [],
18
- undoneAction: [],
17
+ doneAction: [],
18
+ undoneAction: [],
19
19
isTimetraveling: false ,
20
- initialState: {}
20
+ initialState: {}
21
21
}
22
22
},
23
-
24
- created () {
25
23
24
+ created () {
26
25
this .$store .subscribeAction ((action , state ) => {
27
26
// console.log("We are saving this action!", action)
28
- if (typeof action .payload === " object" ) {
27
+ if (typeof action .payload === ' object' ) {
29
28
// console.log("We saved the world with a deepclone!", action.payload === cloneDeep)
30
29
action .payload = cloneDeep (action .payload )
31
30
}
32
31
this .doneAction .push (action)
33
32
// console.log('this is the action we are logging',action)
34
33
// console.log('this is in our redo queue', this.undoneAction[this.undoneAction.length-1])
35
34
// 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 )) {
35
+ if (! this .isTimetraveling ) {
36
+ if (this .undoneAction [this .undoneAction .length - 1 ]) {
37
+ if (action .type == this .undoneAction [this .undoneAction .length - 1 ].type &&
38
+ deepEqual (action .payload , this .undoneAction [this .undoneAction .length - 1 ].payload )) {
40
39
this .undoneAction .pop ()
41
- }
42
- else {
40
+ } else {
43
41
this .undoneAction = []
44
42
}
45
43
}
@@ -48,42 +46,59 @@ let redoMixin = {
48
46
// this.blankState = cloneDeep(this.$store)
49
47
},
50
48
51
- mounted () {
52
- window .addEventListener (" keydown" , event => {
53
- if (event .ctrlKey && event .key === " z " ) {
54
- event .preventDefault ()
49
+ mounted () {
50
+ window .addEventListener (' keydown' , event => {
51
+ if (event .ctrlKey && event .key === ' z ' ) {
52
+ event .preventDefault ()
55
53
this .undo ()
56
54
}
57
- });
58
- window .addEventListener (" keydown" , event => {
59
- if (event .ctrlKey && event .key === " y " ) {
60
- event .preventDefault ()
55
+ })
56
+ window .addEventListener (' keydown' , event => {
57
+ if (event .ctrlKey && event .key === ' y ' ) {
58
+ event .preventDefault ()
61
59
this .redo ()
62
60
}
63
- });
64
- // console.log("do we want this? or this.$store.state?", this.$store.state)
65
- this .initialState = defaultState (this .$store .state )
61
+ })
62
+
63
+ // window.addEventListener('keydown', event => {
64
+ // if (event.ctrlKey && event.key === 'a') {
65
+ // event.preventDefault()
66
+ // if (this.$store.state.activeHTML !== '') {
67
+ // this.$store.dispatch('setActiveLayer', {id:this.$store.state.activeHTML, text:"banana"})
68
+ // }
69
+ // }
70
+ // });
71
+ // window.addEventListener('keydown', event => {
72
+ // if (event.ctrlKey && event.key === 'd') {
73
+ // event.preventDefault()
74
+ // if (this.$store.state.activeLayer.id !== '') {
75
+ // this.$store.dispatch('upOneLayer', this.$store.state.activeLayer.id)
76
+ // }
77
+ // }
78
+ // });
66
79
80
+ // console.log("do we want this? or this.$store.state?", this.$store.state)
81
+ this .initialState = defaultState (this .$store .state )
67
82
},
68
83
69
84
methods: {
70
- undo : function () {
85
+ undo : function () {
71
86
// do {
72
87
// console.log("How far back?")
73
88
74
- this .isTimetraveling = true ;
89
+ this .isTimetraveling = true
75
90
76
91
let undone = this .doneAction .pop ()
77
-
78
- if (undone !== undefined ) {
92
+
93
+ if (undone !== undefined ) {
79
94
this .undoneAction .push (undone)
80
- if (undone .type === " setActiveComponent" ) {
81
- console .log (" We did something useless!" )
82
- do {
95
+ if (undone .type === ' setActiveComponent' ) {
96
+ console .log (' We did something useless!' )
97
+ do {
83
98
this .undoneAction .push (this .doneAction .pop ())
84
99
}
85
- while (this .doneAction [this .doneAction .length - 1 ] &&
86
- (this .doneAction [this .doneAction .length - 1 ].type === " setActiveComponent" ))
100
+ while (this .doneAction [this .doneAction .length - 1 ] &&
101
+ (this .doneAction [this .doneAction .length - 1 ].type === ' setActiveComponent' ))
87
102
}
88
103
}
89
104
@@ -94,38 +109,35 @@ let redoMixin = {
94
109
initialState: this .initialState ,
95
110
store: this .$store
96
111
}
97
- this .$store .commit (" EMPTY_STATE" , payload)
112
+ this .$store .commit (' EMPTY_STATE' , payload)
98
113
console .log (this .$store )
99
114
this .doneAction .forEach (action => {
100
- console .log (" In the loop" , this .$store )
115
+ console .log (' In the loop' , this .$store )
101
116
// 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
-
117
+ this .$store .dispatch (action .type , cloneDeep (action .payload ))
118
+ this .doneAction .pop ()
119
+ })
120
+ this .isTimetraveling = false
107
121
},
108
- redo : function () {
109
-
122
+ redo : function () {
110
123
let action = this .undoneAction .pop ()
111
- this .isTimetraveling = true ;
112
- if (action) {
124
+ this .isTimetraveling = true
125
+ if (action) {
113
126
this .$store .dispatch (action .type , cloneDeep (action .payload ))
114
127
}
115
- this .isTimetraveling = false ;
116
- if (action && (action .type === " setActiveComponent" )) {
117
- console .log (" WE GOTTA DO MORE" )
118
- this .redo ();
128
+ this .isTimetraveling = false
129
+ if (action && (action .type === ' setActiveComponent' )) {
130
+ console .log (' WE GOTTA DO MORE' )
131
+ this .redo ()
119
132
}
120
133
}
121
134
122
135
}
123
136
}
124
137
125
-
126
138
export default {
127
139
name: ' App' ,
128
- mixins: [redoMixin]
140
+ mixins: [redoMixin]
129
141
}
130
142
</script >
131
143
0 commit comments