Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[QUESTION] - Store Paho.MQTT.Client in REDUX store #16

Open
dittmarconsulting opened this issue Jan 3, 2018 · 3 comments
Open

[QUESTION] - Store Paho.MQTT.Client in REDUX store #16

dittmarconsulting opened this issue Jan 3, 2018 · 3 comments

Comments

@dittmarconsulting
Copy link

dittmarconsulting commented Jan 3, 2018

Hi there,

I have successfully implemented the package and love it. Great work.

Right now I have stored the client object in the local store as shown in the example but when I try to store the object in the REDUX store I get only an empty object.

Here a simple example

constructor(props) {
        super(props)

        const client = new Paho.MQTT.Client(<IP>, <PORT>, <CLIENT ID>)
        client.onConnectionLost = this._onConnectionLost
        client.onMessageArrived = this._onMessageArrived
        client.connect({
            onSuccess: this._onConnect,
            useSSL: true
        })
        this.props.setMQTTClient(client)

Where setMQTTClient() is the action that invokes the reducer to write it to the client to the store.

Since I'm getting an empty object I'm wondering whether the client creation is Promised based. If yes, how can I hook on the callback so that I can save the entire object once it has been created.

@idlesong
Copy link

+1

@cltsang
Copy link

cltsang commented Oct 5, 2018

There is not quite enough information to look into your problem.
But my recommendation is if you'd like to manage the mqtt client object with redux, then it should be created and destroyed in a redux action creator as well, such that React components don't have to access MQTT-related code directly at all.
If you could provide at least your reducer and action creator, maybe I could try to help.

@badcodercpp
Copy link

While storing connected mqtt client to redux, its always a good idea to inject the client object to the redux store via middleware, and this feature is out of scope for this project as I guess. So I write a middleware to solve this issue, please have a look at this - https://www.npmjs.com/package/redux-mqtt
This middleware works well with this package to store mqtt client.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants