inProgress-team / react-native-meteor

Meteor Reactivity for your React Native application :)
MIT License
693 stars 210 forks source link

Subscribe in redux-thunk action creator #291

Closed rgstephens closed 6 years ago

rgstephens commented 6 years ago

I'd to keep the my Meteor interactions in a redux action creator using redux-thunk. Using Meteor.ddp.on("added"..., I can see that the data is being retrieved but the Meteor.collection('keys').find() returns null.

I suspect this is because the call is not wrapped in createContainer but I don't want to do the updates in a React component. Is it possible to maintain a redux store with Meteor data in this way?

export const getKeys = () => {
    const keysSubscription = Meteor.subscribe('keys');
    Meteor.subscribe("keys", {
        onReady: function () {
            console.log('Meteor subscribe ready!');
            const keys = Meteor.collection('keys').find();
            console.log('Meteor keys: ', keys);
            return (dispatch, getState) => {
                dispatch({
                    type: 'GET_KEYS',
                    keys: keys
                });
            }
        },
        onStop: function () {
            console.log("Meteor onStop: ", arguments);
        }
    });
}
rgstephens commented 6 years ago

There was a problem with the server publication.