-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Refactor application store architecture
- Loading branch information
1 parent
c40da05
commit 43eea79
Showing
9 changed files
with
202 additions
and
122 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
--- | ||
"wpgraphql-ide": major | ||
--- | ||
|
||
Refactored stores, including renaming 'wpgraphql-ide' to 'wpgraphql-ide/app', and adding additional stores such as 'wpgraphql-ide/editor-toolbar |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,109 @@ | ||
import { createReduxStore } from '@wordpress/data'; | ||
|
||
const initialState = { | ||
isDrawerOpen: false, | ||
shouldRenderStandalone: false, | ||
isInitialStateLoaded: false, | ||
registeredPlugins: {}, | ||
query: null, | ||
}; | ||
|
||
const reducer = ( state = initialState, action ) => { | ||
switch ( action.type ) { | ||
case 'SET_RENDER_STANDALONE': | ||
return { | ||
...state, | ||
shouldRenderStandalone: action.shouldRenderStandalone, | ||
}; | ||
case 'SET_QUERY': | ||
return { | ||
...state, | ||
query: action.query, | ||
}; | ||
case 'SET_DRAWER_OPEN': | ||
return { | ||
...state, | ||
isDrawerOpen: action.isDrawerOpen, | ||
}; | ||
case 'SET_INITIAL_STATE_LOADED': | ||
return { | ||
...state, | ||
isInitialStateLoaded: true, | ||
}; | ||
case 'REGISTER_PLUGIN': | ||
return { | ||
...state, | ||
registeredPlugins: { | ||
...state.registeredPlugins, | ||
[ action.name ]: action.config, | ||
}, | ||
}; | ||
} | ||
return state; | ||
}; | ||
const actions = { | ||
setQuery: ( query ) => { | ||
return { | ||
type: 'SET_QUERY', | ||
query, | ||
}; | ||
}, | ||
setDrawerOpen: ( isDrawerOpen ) => { | ||
return { | ||
type: 'SET_DRAWER_OPEN', | ||
isDrawerOpen, | ||
}; | ||
}, | ||
setShouldRenderStandalone: ( shouldRenderStandalone ) => { | ||
return { | ||
type: 'SET_RENDER_STANDALONE', | ||
shouldRenderStandalone, | ||
}; | ||
}, | ||
setInitialStateLoaded: () => { | ||
return { | ||
type: 'SET_INITIAL_STATE_LOADED', | ||
}; | ||
}, | ||
registerPlugin: ( name, config ) => { | ||
return { | ||
type: 'REGISTER_PLUGIN', | ||
name, | ||
config, | ||
}; | ||
}, | ||
}; | ||
|
||
const selectors = { | ||
getQuery: ( state ) => { | ||
return state.query; | ||
}, | ||
isDrawerOpen: ( state ) => { | ||
return state.isDrawerOpen; | ||
}, | ||
shouldRenderStandalone: ( state ) => { | ||
return state.shouldRenderStandalone; | ||
}, | ||
isInitialStateLoaded: ( state ) => { | ||
return state.isInitialStateLoaded; | ||
}, | ||
getPluginsArray: ( state ) => { | ||
const registeredPlugins = state.registeredPlugins; | ||
const pluginsArray = []; | ||
Object.entries( registeredPlugins ).map( ( [ key, config ] ) => { | ||
const plugin = () => { | ||
return config; | ||
}; | ||
pluginsArray.push( plugin() ); | ||
} ); | ||
return pluginsArray; | ||
}, | ||
}; | ||
|
||
const store = createReduxStore( 'wpgraphql-ide/app', { | ||
reducer, | ||
selectors, | ||
actions, | ||
} ); | ||
|
||
export default store; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
import { createReduxStore } from '@wordpress/data'; | ||
|
||
const initialState = { | ||
buttons: [] | ||
}; | ||
|
||
const reducer = ( state = initialState, action ) => { | ||
switch ( action.type ) { | ||
case 'REGISTER_BUTTON': | ||
return { | ||
...state, | ||
buttons: state.buttons.push(action.name), | ||
}; | ||
} | ||
return state; | ||
}; | ||
|
||
const actions = { | ||
registerButton: ( name, config ) => { | ||
return { | ||
type: 'REGISTER_BUTTON', | ||
name, | ||
config, | ||
}; | ||
} | ||
}; | ||
|
||
const selectors = { | ||
buttons: ( state ) => { | ||
return state.buttons; | ||
} | ||
}; | ||
|
||
const store = createReduxStore( 'wpgraphql-ide/editor-toolbar', { | ||
reducer, | ||
selectors, | ||
actions, | ||
} ); | ||
|
||
export default store; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,107 +1,31 @@ | ||
import { createReduxStore } from '@wordpress/data'; | ||
|
||
const initialState = { | ||
isDrawerOpen: false, | ||
shouldRenderStandalone: false, | ||
isInitialStateLoaded: false, | ||
registeredPlugins: {}, | ||
query: null, | ||
}; | ||
|
||
const reducer = ( state = initialState, action ) => { | ||
switch ( action.type ) { | ||
case 'SET_RENDER_STANDALONE': | ||
return { | ||
...state, | ||
shouldRenderStandalone: action.shouldRenderStandalone, | ||
}; | ||
case 'SET_QUERY': | ||
return { | ||
...state, | ||
query: action.query, | ||
}; | ||
case 'SET_DRAWER_OPEN': | ||
return { | ||
...state, | ||
isDrawerOpen: action.isDrawerOpen, | ||
}; | ||
case 'SET_INITIAL_STATE_LOADED': | ||
return { | ||
...state, | ||
isInitialStateLoaded: true, | ||
}; | ||
case 'REGISTER_PLUGIN': | ||
return { | ||
...state, | ||
registeredPlugins: { | ||
...state.registeredPlugins, | ||
[ action.name ]: action.config, | ||
}, | ||
}; | ||
} | ||
return state; | ||
}; | ||
const actions = { | ||
setQuery: ( query ) => { | ||
return { | ||
type: 'SET_QUERY', | ||
query, | ||
}; | ||
}, | ||
setDrawerOpen: ( isDrawerOpen ) => { | ||
return { | ||
type: 'SET_DRAWER_OPEN', | ||
isDrawerOpen, | ||
}; | ||
}, | ||
setShouldRenderStandalone: ( shouldRenderStandalone ) => { | ||
return { | ||
type: 'SET_RENDER_STANDALONE', | ||
shouldRenderStandalone, | ||
}; | ||
}, | ||
setInitialStateLoaded: () => { | ||
return { | ||
type: 'SET_INITIAL_STATE_LOADED', | ||
}; | ||
}, | ||
registerPlugin: ( name, config ) => { | ||
return { | ||
type: 'REGISTER_PLUGIN', | ||
name, | ||
config, | ||
}; | ||
}, | ||
}; | ||
|
||
const selectors = { | ||
getQuery: ( state ) => { | ||
return state.query; | ||
}, | ||
isDrawerOpen: ( state ) => { | ||
return state.isDrawerOpen; | ||
}, | ||
shouldRenderStandalone: ( state ) => { | ||
return state.shouldRenderStandalone; | ||
}, | ||
isInitialStateLoaded: ( state ) => { | ||
return state.isInitialStateLoaded; | ||
}, | ||
getPluginsArray: ( state ) => { | ||
const registeredPlugins = state.registeredPlugins; | ||
const pluginsArray = []; | ||
Object.entries( registeredPlugins ).map( ( [ key, config ] ) => { | ||
const plugin = () => { | ||
return config; | ||
}; | ||
pluginsArray.push( plugin() ); | ||
} ); | ||
return pluginsArray; | ||
}, | ||
}; | ||
|
||
export const store = createReduxStore( 'wpgraphql-ide', { | ||
reducer, | ||
selectors, | ||
actions, | ||
} ); | ||
import { register, dispatch } from '@wordpress/data'; | ||
|
||
import appStore from './app-store'; | ||
import editorToolbarStore from './editor-toolbar-store'; | ||
|
||
export function registerStores() { | ||
register( appStore ); | ||
register( editorToolbarStore ); | ||
} | ||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
// TEST FUNCTION | ||
export function registerEditorToolbarButton( name, config ) { | ||
console.log({ name, config }); | ||
dispatch( editorToolbarStore ).registerButton( name, config ); | ||
} |