Refactor communication
Add QoS andd retain flag Refactor reducer
This commit is contained in:
@@ -32,7 +32,7 @@ export const showError = (error?: string) => ({
|
||||
})
|
||||
|
||||
export const disconnect = () => (dispatch: Dispatch<CustomAction>, getState: () => AppState) => {
|
||||
rendererEvents.emit(removeConnection, getState().connectionId)
|
||||
rendererEvents.emit(removeConnection, getState().tooBigReducer.connectionId)
|
||||
|
||||
dispatch({
|
||||
type: ActionTypes.disconnect,
|
||||
|
||||
61
app/src/actions/Publish.ts
Normal file
61
app/src/actions/Publish.ts
Normal file
@@ -0,0 +1,61 @@
|
||||
import { ActionTypes, Action } from '../reducers/Publish'
|
||||
import { AppState } from '../reducers'
|
||||
import { Dispatch } from 'redux'
|
||||
import { rendererEvents, makePublishEvent } from '../../../events'
|
||||
|
||||
export const setTopic = (topic?: string): Action => {
|
||||
return {
|
||||
topic,
|
||||
type: ActionTypes.PUBLISH_SET_TOPIC,
|
||||
}
|
||||
}
|
||||
|
||||
export const setPayload = (payload?: string): Action => {
|
||||
return {
|
||||
payload,
|
||||
type: ActionTypes.PUBLISH_SET_PAYLOAD,
|
||||
}
|
||||
}
|
||||
|
||||
export const toggleEmptyPayload = (): Action => {
|
||||
return {
|
||||
type: ActionTypes.PUBLISH_TOGGLE_EMPTY_PAYLOAD,
|
||||
}
|
||||
}
|
||||
|
||||
export const setQoS = (qos: 0 | 1 | 2): Action => {
|
||||
return {
|
||||
qos,
|
||||
type: ActionTypes.PUBLISH_SET_QOS,
|
||||
}
|
||||
}
|
||||
|
||||
export const setEditorMode = (editorMode: string): Action => {
|
||||
return {
|
||||
editorMode,
|
||||
type: ActionTypes.PUBLISH_SET_EDITOR_MODE,
|
||||
}
|
||||
}
|
||||
|
||||
export const publish = (connectionId: string) => (dispatch: Dispatch<Action>, getState: () => AppState) => {
|
||||
const state = getState()
|
||||
const topic = state.publish.topic
|
||||
|
||||
if (!topic) {
|
||||
return
|
||||
}
|
||||
|
||||
const publishEvent = makePublishEvent(connectionId)
|
||||
rendererEvents.emit(publishEvent, {
|
||||
topic,
|
||||
payload: state.publish.payload,
|
||||
retain: state.publish.retain,
|
||||
qos: state.publish.qos,
|
||||
})
|
||||
}
|
||||
|
||||
export const toggleRetain = (): Action => {
|
||||
return {
|
||||
type: ActionTypes.PUBLISH_TOGGLE_RETAIN,
|
||||
}
|
||||
}
|
||||
@@ -1,15 +0,0 @@
|
||||
import { ActionTypes, CustomAction } from '../reducers'
|
||||
|
||||
export const setPublishTopic = (topic: string): CustomAction => {
|
||||
return {
|
||||
publishTopic: topic,
|
||||
type: ActionTypes.setPublishTopic,
|
||||
}
|
||||
}
|
||||
|
||||
export const setPublishPayload = (payload: string): CustomAction => {
|
||||
return {
|
||||
publishPayload: payload,
|
||||
type: ActionTypes.setPublishPayload,
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
import * as settingsActions from './Settings'
|
||||
import * as sidebarActions from './Sidebar'
|
||||
import * as publishActions from './Publish'
|
||||
import * as treeActions from './Tree'
|
||||
import * as updateNotifierActions from './UpdateNotifier'
|
||||
import * as connectionActions from './Connection'
|
||||
|
||||
export { settingsActions, treeActions, sidebarActions, updateNotifierActions, connectionActions }
|
||||
export { settingsActions, treeActions, publishActions, updateNotifierActions, connectionActions }
|
||||
|
||||
Reference in New Issue
Block a user