Skip to content

Commit 823ed22

Browse files
committed
made the default state dynamically generated on initialization
1 parent 0944cb8 commit 823ed22

File tree

4 files changed

+76
-47
lines changed

4 files changed

+76
-47
lines changed

src/App.vue

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,15 +8,16 @@
88
import { SET_ACTIVE_COMPONENT } from './store/types'
99
const deepEqual = require('lodash.isequal')
1010
const cloneDeep = require('lodash.clonedeep')
11-
11+
import {defaultState} from './store/state/index.js'
1212
1313
let redoMixin = {
1414
data() {
1515
return {
1616
// banana:[],
1717
doneAction:[],
1818
undoneAction:[],
19-
isTimetraveling: false
19+
isTimetraveling: false,
20+
initialState:{}
2021
}
2122
},
2223
@@ -60,6 +61,9 @@ let redoMixin = {
6061
this.redo()
6162
}
6263
});
64+
//console.log("do we want this? or this.$store.state?", this.$store.state)
65+
this.initialState = defaultState(this.$store.state)
66+
6367
},
6468
6569
methods: {
@@ -86,7 +90,11 @@ let redoMixin = {
8690
// while (this.doneAction[this.doneAction.length-1] &&
8791
// (this.doneAction[this.doneAction.length - 1].type === "setActiveComponent" ||
8892
// this.doneAction[this.doneAction.length - 1].type === "updateComponentPosition" ))
89-
this.$store.commit("EMPTY_STATE",this.$store)
93+
let payload = {
94+
initialState: this.initialState,
95+
store: this.$store
96+
}
97+
this.$store.commit("EMPTY_STATE",payload)
9098
console.log(this.$store)
9199
this.doneAction.forEach(action => {
92100
console.log("In the loop",this.$store)

src/components/ComponentDisplay.vue

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -252,7 +252,7 @@ export default {
252252
routeArray: this.routes[this.activeRoute],
253253
activeComponentData: this.activeComponentData
254254
}
255-
console.log("x: ",payload.x,"y:",payload.y)
255+
console.log("x: ",payload.x,"y: ",payload.y)
256256
//this.updateStartingPosition(payload);
257257
},
258258

src/store/mutations.js

Lines changed: 43 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import * as types from './types'
22
import icons from './state/icons.js'
33
import htmlElementMap from './state/htmlElementMap.js'
4+
const cloneDeep = require('lodash.clonedeep')
45
// import VuexStore from './index'
56
// import { getDefault, defaultState } from './state/index.js'
67

@@ -80,47 +81,48 @@ const mutations = {
8081
},
8182
// empty state
8283
[types.EMPTY_STATE]: (state, payload) => {
83-
console.log('This is our defaultstate still', defaultState)
84-
console.log(payload)
85-
payload.replaceState({
86-
icons,
87-
htmlElementMap,
88-
// every single time we create a component
89-
// sent to export project component
90-
componentMap: {
91-
App: {
92-
componentName: 'App',
93-
children: ['HomeView'],
94-
htmlList: []
95-
},
96-
HomeView: {
97-
componentName: 'HomeView',
98-
children: [],
99-
htmlList: []
100-
}
101-
// NewView: {}
102-
},
103-
routes: {
104-
HomeView: []
105-
// NewView: []
106-
},
107-
userActions: [],
108-
userState: {},
109-
/**
110-
*
111-
*/
112-
componentNameInputValue: '',
113-
projects: [{ filename: 'Untitled-1', lastSavedLocation: '' }],
114-
activeRoute: 'HomeView',
115-
activeComponent: '',
116-
selectedElementList: [],
117-
projectNumber: 2,
118-
activeTab: 0,
119-
componentChildrenMultiselectValue: [],
120-
modalOpen: false,
121-
parentSelected: false,
122-
imagePath: ''
123-
})
84+
// console.log('This is our defaultstate still', defaultState)
85+
console.log("hopefully this stays pure", payload)
86+
payload.store.replaceState(cloneDeep(payload.initialState))
87+
// {
88+
// icons,
89+
// htmlElementMap,
90+
// // every single time we create a component
91+
// // sent to export project component
92+
// componentMap: {
93+
// App: {
94+
// componentName: 'App',
95+
// children: ['HomeView'],
96+
// htmlList: []
97+
// },
98+
// HomeView: {
99+
// componentName: 'HomeView',
100+
// children: [],
101+
// htmlList: []
102+
// }
103+
// // NewView: {}
104+
// },
105+
// routes: {
106+
// HomeView: []
107+
// // NewView: []
108+
// },
109+
// userActions: [],
110+
// userState: {},
111+
// /**
112+
// *
113+
// */
114+
// componentNameInputValue: '',
115+
// projects: [{ filename: 'Untitled-1', lastSavedLocation: '' }],
116+
// activeRoute: 'HomeView',
117+
// activeComponent: '',
118+
// selectedElementList: [],
119+
// projectNumber: 2,
120+
// activeTab: 0,
121+
// componentChildrenMultiselectValue: [],
122+
// modalOpen: false,
123+
// parentSelected: false,
124+
// imagePath: ''
125+
// })
124126
},
125127

126128
// add parent

src/store/state/index.js

Lines changed: 21 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -39,9 +39,27 @@ const newState = {
3939
componentChildrenMultiselectValue: [],
4040
modalOpen: false,
4141
parentSelected: false,
42-
imagePath: ''
42+
imagePath: {
43+
HomeView:'',
44+
}
4345
}
4446

47+
//closured method to ensure we only ever write the default state ONCE
48+
const writeTheDefault = () => {
49+
let initial = {}
50+
let needsToRun = true;
51+
function onced(payload){
52+
if(needsToRun){
53+
initial = cloneDeep(payload)
54+
needsToRun = false;
55+
}
56+
return initial
57+
}
58+
return onced
59+
}
60+
61+
const defaultState = writeTheDefault()
62+
4563
// const defaultState =
4664
// {
4765
// icons,
@@ -89,4 +107,5 @@ const newState = {
89107

90108

91109

92-
export default newState
110+
export default newState
111+
export {defaultState}

0 commit comments

Comments
 (0)