Add global state and right click menu using redux
This commit is contained in:
parent
9821373504
commit
54d64cc124
10 changed files with 190 additions and 81 deletions
31
app/reducers/contextMenu.jsx
Normal file
31
app/reducers/contextMenu.jsx
Normal file
|
|
@ -0,0 +1,31 @@
|
|||
import { UPDATE_CONTEXT_MENU, OPEN_CONTEXT_MENU, CLOSE_CONTEXT_MENU } from '../constants'
|
||||
|
||||
|
||||
const initialState =
|
||||
{
|
||||
opened: false,
|
||||
x: 0,
|
||||
y: 0,
|
||||
items: []
|
||||
}
|
||||
|
||||
export default function contextMenu(state = initialState, action){
|
||||
switch (action.type) {
|
||||
case UPDATE_CONTEXT_MENU:
|
||||
return Object.assign({}, state,{
|
||||
items: action.items
|
||||
})
|
||||
case OPEN_CONTEXT_MENU:
|
||||
return Object.assign({}, state, {
|
||||
opened: true,
|
||||
x: action.x,
|
||||
y: action.y
|
||||
})
|
||||
case CLOSE_CONTEXT_MENU:
|
||||
return Object.assign({}, state, {
|
||||
opened: false
|
||||
})
|
||||
default:
|
||||
return state
|
||||
}
|
||||
}
|
||||
8
app/reducers/index.jsx
Normal file
8
app/reducers/index.jsx
Normal file
|
|
@ -0,0 +1,8 @@
|
|||
import { combineReducers } from 'redux'
|
||||
import contextMenu from './contextMenu'
|
||||
|
||||
const rootReducer = combineReducers({
|
||||
contextMenu
|
||||
})
|
||||
|
||||
export default rootReducer
|
||||
Loading…
Add table
Add a link
Reference in a new issue