fix subscriptions, now called messageChannels

This commit is contained in:
Jonathan Rainville 2018-08-08 15:09:40 -04:00 committed by Iuri Matias
parent a52bbcac05
commit 5d126c8caa
5 changed files with 13 additions and 7 deletions

View File

@ -113,7 +113,7 @@ export const messageSend = {
export const MESSAGE_LISTEN = createRequestTypes('MESSAGE_LISTEN');
export const messageListen = {
request: (channel) => action(MESSAGE_LISTEN[REQUEST], {channel}),
request: (messageChannel) => action(MESSAGE_LISTEN[REQUEST], {messageChannels: [messageChannel]}),
success: (messages) => action(MESSAGE_LISTEN[SUCCESS], {messages}),
failure: (error) => action(MESSAGE_LISTEN[FAILURE], {error})
};

View File

@ -5,7 +5,7 @@ import {Alert, Loader, Page} from 'tabler-react';
import {messageSend, messageListen, messageVersion} from "../actions";
import Communication from "../components/Communication";
import Loading from "../components/Loading";
import {getMessageVersion, getMessages} from "../reducers/selectors";
import {getMessageVersion, getMessages, getMessageChannels} from "../reducers/selectors";
class CommunicationContainer extends Component {
componentDidMount() {
@ -40,7 +40,7 @@ class CommunicationContainer extends Component {
<Communication listenToMessages={(channel) => this.listenToChannel(channel)}
sendMessage={(channel, message) => this.sendMessage(channel, message)}
channels={this.props.messages}
subscriptions={this.props.messages.subscriptions}/>
subscriptions={this.props.messageChannels}/>
</Page.Content>
);
}
@ -51,12 +51,14 @@ CommunicationContainer.propTypes = {
messageListen: PropTypes.func,
communicationVersion: PropTypes.func,
messageVersion: PropTypes.number,
messages: PropTypes.object
messages: PropTypes.object,
messageChannels: PropTypes.array
};
function mapStateToProps(state) {
return {
messages: getMessages(state),
messageChannels: getMessageChannels(state),
messageVersion: getMessageVersion(state)
};
}

View File

@ -13,7 +13,7 @@ const entitiesDefaultState = {
contractProfiles: [],
commands: [],
messages: [],
subscriptions: [],
messageChannels: [],
messageVersion: null
};

View File

@ -62,6 +62,10 @@ export function getMessageVersion(state) {
return state.entities.messageVersion;
}
export function getMessageChannels(state) {
return state.entities.messageChannels;
}
export function getMessages(state) {
const messages = {};
state.entities.messages.forEach(message => {

View File

@ -121,11 +121,11 @@ export function *watchSendMessage() {
}
export function *listenToMessages(action) {
const socket = api.listenToChannel(action.channel);
const socket = api.listenToChannel(action.messageChannels[0]);
const channel = yield call(createChannel, socket);
while (true) {
const message = yield take(channel);
yield put(messageListen.success([{channel: action.channel, message: message.data, time: message.time}]));
yield put(messageListen.success([{channel: action.messageChannels[0], message: message.data, time: message.time}]));
}
}