I am using flux with authobahn and I have problems with my architecture. I have some components that get their status by subscribing to the pubsub theme.
I am currently using flux for my data, and my actions are as follows:
window.AutobahnSession = ..;
var RoomsActions = {
subscribeToRoom: function(roomName) {
var onData = function(data) {
Dispatcher.dispatch({
type: "ROOM_MESSAGE_ARRIVED",
message: data,
roomName: roomName
});
};
var subscription = window.AutobahnSession.subscribe('rooms/' + roomName, onData);
Dispatcher.dispatch({
type: "ROOM_SUBSCRIPTION_CREATED",
subscription: subscription,
roomName: roomName
});
},
unsubscribeToRoom: function(roomName) {
Dispatcher.dispatch({
type: "UNSUBSCRIBE_TO_ROOM",
roomName: roomName
});
}
};
RoomsStore.dispatchToken = ChatAppDispatcher.register(function(action) {
switch(action.type) {
case "ROOM_MESSAGE_ARRIVED":
break;
case "ROOM_SUBSCRIPTION_CREATED":
break;
case "UNSUBSCRIBE_TO_ROOM":
break;
}
});
Is this the right way to handle your subscription? I donβt really like the idea of ββa subscribeToRoom action, which always listens for events and sends a subscription to the dispatcher.
source
share