function getStateOrDevice(state, ownProps) { switch (state.active.activeTab) { case "Devices": return state.devices[ownProps.id]; case "Scenes": return state.sceneStates[ownProps.id]; case "Hosts": return state.hostDevices[ownProps.hostId][ownProps.id]; default: throw new Error( `stateOrDevice has no value in tab "${state.active.activeTab}"` ); } } function getDevice(state, ownProps) { switch (state.active.activeTab) { case "Scenes": return state.devices[getStateOrDevice(state, ownProps).deviceId]; case "Devices": case "Hosts": return getStateOrDevice(state, ownProps); default: throw new Error(`device has no value in tab "${state.active.activeTab}"`); } } function getRoomName(state, ownProps) { switch (state.active.activeTab) { case "Scenes": case "Devices": return (state.rooms[getDevice(state, ownProps).roomId] || {}).name; case "Hosts": return "Room Name not implemented yet"; } } export default function mapStateToProps(state, ownProps) { return { get stateOrDevice() { return getStateOrDevice(state, ownProps); }, get device() { return getDevice(state, ownProps); }, get roomName() {}, get type() { return getDevice(state, ownProps).kind; }, }; }