forked from openblockcc/openblock-gui
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Добавление возможности подключения нескольких устройств.
- Loading branch information
s.gologuzov
committed
Mar 27, 2024
1 parent
c603612
commit 59fd3a9
Showing
6 changed files
with
99 additions
and
48 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
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,44 @@ | ||
const ADD_DEVICE = 'scratch-gui/devices/add'; | ||
const REMOVE_DEVICE = 'scratch-gui/devices/remove'; | ||
|
||
const initialState = { | ||
}; | ||
|
||
const reducer = function (state, action) { | ||
if (typeof state === 'undefined') state = initialState; | ||
const newState = Object.assign({}, state); | ||
switch (action.type) { | ||
case ADD_DEVICE: { | ||
newState[action.deviceId] = action.device; | ||
return newState; | ||
} | ||
case REMOVE_DEVICE: { | ||
delete newState[action.deviceId]; | ||
return newState; | ||
} | ||
default: | ||
return state; | ||
} | ||
}; | ||
|
||
const addDevice = function (device) { | ||
return { | ||
type: ADD_DEVICE, | ||
deviceId: device.deviceId, | ||
device: device | ||
}; | ||
}; | ||
|
||
const removeDevice = function (deviceId) { | ||
return { | ||
type: REMOVE_DEVICE, | ||
deviceId: deviceId | ||
}; | ||
}; | ||
|
||
export { | ||
reducer as default, | ||
initialState as devicesInitialState, | ||
addDevice, | ||
removeDevice | ||
}; |
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