@@ -23,84 +23,58 @@ import Vue from 'vue';
2323import Vuex from 'vuex' ;
2424import VuexPersistence from 'vuex-persist' ;
2525import {
26+ // graph
27+ getGraphDefaultState ,
28+ graphGetters ,
29+ graphMutations ,
30+
31+ // settings
2632 getSettingsWorkflowHistoryDefaultState ,
27- getWorkflowHistoryDefaultState ,
2833 settingsWorkflowHistoryGetters ,
2934 settingsWorkflowHistoryMutations ,
30- } from '~containers' ;
3135
32- // Graph store
36+ // workflow history
37+ getWorkflowHistoryDefaultState ,
38+ } from '~containers' ;
3339
34- const getGraphDefaultState = ( ) => ( {
35- childRoute : null ,
36- newExecutionId : null ,
37- parentRoute : null ,
38- hasChildBtn : false ,
39- childBtnText : null ,
40- parentBtnText : 'to parent' ,
40+ const getDefaultState = ( state = { } ) => ( {
41+ graph : getGraphDefaultState ( state . graph ) ,
42+ settingsWorkflowHistory : getSettingsWorkflowHistoryDefaultState (
43+ state . settingsWorkflowHistory
44+ ) ,
45+ workflowHistory : getWorkflowHistoryDefaultState ( state . workflowHistory ) ,
4146} ) ;
4247
43- const graphMutations = {
44- childRoute ( state , param ) {
45- state . graph . childRoute = param . route ;
46- state . graph . hasChildBtn = true ;
47- state . graph . childBtnText = param . btnText ;
48- } ,
49- newExecutionRoute ( state , route ) {
50- ( state . graph . newExecutionId = route ) ,
51- ( state . graph . hasChildBtn = ! state . graph . hasChildBtn ) ;
52- } ,
53- previousExecutionRoute ( state , route ) {
54- ( state . graph . parentRoute = route ) ,
55- ( state . graph . parentBtnText = 'previous execution' ) ;
56- } ,
57- toggleChildBtn ( state ) {
58- state . graph . hasChildBtn = false ;
59- } ,
60- parentRoute ( state , route ) {
61- state . graph . parentRoute = route ;
62- } ,
63- resetGraphState ( state ) {
64- Object . assign ( state . graph , getGraphDefaultState ( ) ) ;
65- } ,
66- } ;
48+ const getStoreConfig = ( { state } ) => {
49+ const initialState = getDefaultState ( state ) ;
6750
68- const graphGetters = {
69- childRoute : state => state . graph . childRoute ,
70- newExecutionId : state => state . graph . newExecutionId ,
71- hasChildBtn : state => state . graph . hasChildBtn ,
72- childBtnText : state => state . graph . childBtnText ,
73- parentBtnText : state => state . graph . parentBtnText ,
74- parentRoute : state => state . graph . parentRoute ,
75- } ;
51+ const vuexLocal = new VuexPersistence ( {
52+ storage : window . localStorage ,
53+ } ) ;
7654
77- // Application store
55+ const storeConfig = {
56+ state : initialState ,
57+ mutations : {
58+ ...graphMutations ,
59+ ...settingsWorkflowHistoryMutations ,
60+ } ,
61+ getters : {
62+ ...graphGetters ,
63+ ...settingsWorkflowHistoryGetters ,
64+ } ,
65+ plugins : [ vuexLocal . plugin ] ,
66+ } ;
7867
79- const getDefaultState = ( ) => ( {
80- graph : getGraphDefaultState ( ) ,
81- settingsWorkflowHistory : getSettingsWorkflowHistoryDefaultState ( ) ,
82- workflowHistory : getWorkflowHistoryDefaultState ( ) ,
83- } ) ;
84-
85- const state = getDefaultState ( ) ;
68+ return storeConfig ;
69+ } ;
8670
87- Vue . use ( Vuex ) ;
71+ const initStore = ( { state } = { } ) => {
72+ Vue . use ( Vuex ) ;
8873
89- const vuexLocal = new VuexPersistence ( {
90- storage : window . localStorage ,
91- } ) ;
74+ const storeConfig = getStoreConfig ( { state } ) ;
75+ const store = new Vuex . Store ( storeConfig ) ;
9276
93- const store = new Vuex . Store ( {
94- state : state ,
95- mutations : {
96- ...graphMutations ,
97- ...settingsWorkflowHistoryMutations ,
98- } ,
99- getters : {
100- ...graphGetters ,
101- ...settingsWorkflowHistoryGetters ,
102- } ,
103- plugins : [ vuexLocal . plugin ] ,
104- } ) ;
77+ return store ;
78+ } ;
10579
106- export default store ;
80+ export default initStore ;
0 commit comments