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 854ef452f7
commit 3ec9dd0667
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 MESSAGE_LISTEN = createRequestTypes('MESSAGE_LISTEN');
export const messageListen = { 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}), success: (messages) => action(MESSAGE_LISTEN[SUCCESS], {messages}),
failure: (error) => action(MESSAGE_LISTEN[FAILURE], {error}) 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 {messageSend, messageListen, messageVersion} from "../actions";
import Communication from "../components/Communication"; import Communication from "../components/Communication";
import Loading from "../components/Loading"; import Loading from "../components/Loading";
import {getMessageVersion, getMessages} from "../reducers/selectors"; import {getMessageVersion, getMessages, getMessageChannels} from "../reducers/selectors";
class CommunicationContainer extends Component { class CommunicationContainer extends Component {
componentDidMount() { componentDidMount() {
@ -40,7 +40,7 @@ class CommunicationContainer extends Component {
<Communication listenToMessages={(channel) => this.listenToChannel(channel)} <Communication listenToMessages={(channel) => this.listenToChannel(channel)}
sendMessage={(channel, message) => this.sendMessage(channel, message)} sendMessage={(channel, message) => this.sendMessage(channel, message)}
channels={this.props.messages} channels={this.props.messages}
subscriptions={this.props.messages.subscriptions}/> subscriptions={this.props.messageChannels}/>
</Page.Content> </Page.Content>
); );
} }
@ -51,12 +51,14 @@ CommunicationContainer.propTypes = {
messageListen: PropTypes.func, messageListen: PropTypes.func,
communicationVersion: PropTypes.func, communicationVersion: PropTypes.func,
messageVersion: PropTypes.number, messageVersion: PropTypes.number,
messages: PropTypes.object messages: PropTypes.object,
messageChannels: PropTypes.array
}; };
function mapStateToProps(state) { function mapStateToProps(state) {
return { return {
messages: getMessages(state), messages: getMessages(state),
messageChannels: getMessageChannels(state),
messageVersion: getMessageVersion(state) messageVersion: getMessageVersion(state)
}; };
} }

View File

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

View File

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

View File

@ -121,11 +121,11 @@ export function *watchSendMessage() {
} }
export function *listenToMessages(action) { export function *listenToMessages(action) {
const socket = api.listenToChannel(action.channel); const socket = api.listenToChannel(action.messageChannels[0]);
const channel = yield call(createChannel, socket); const channel = yield call(createChannel, socket);
while (true) { while (true) {
const message = yield take(channel); 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}]));
} }
} }