inProgress-team / react-native-meteor

Meteor Reactivity for your React Native application :)

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Subscribe in redux-thunk action creator

rgstephens opened this issue · comments

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);
        }
    });
}

There was a problem with the server publication.