Skip to content

Commit

Permalink
a couple small fixes to example and added logic
Browse files Browse the repository at this point in the history
  • Loading branch information
Julian Kingman committed Feb 19, 2017
1 parent 7b4b01d commit 0cc659a
Show file tree
Hide file tree
Showing 5 changed files with 21 additions and 15 deletions.
2 changes: 1 addition & 1 deletion .npmignore
Original file line number Diff line number Diff line change
@@ -1 +1 @@
./example
example
8 changes: 6 additions & 2 deletions connectMeteorRedux.js
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ const meteorReduxReducers = (state = {}, action) => {
ready: action.ready,
}
case 'persist/REHYDRATE':
if (typeof Meteor.ddp === undefined || Meteor.ddp.status === "disconnected") {
if (typeof Meteor.ddp === 'undefined' || Meteor.ddp.status === 'disconnected') {
return action.payload;
}
case 'HARDRESET':
Expand Down Expand Up @@ -134,7 +134,11 @@ const initMeteorRedux = (preloadedState = undefined, enhancer = undefined) => {
const {collection, id, fields} = obj;
fields._id = id;
const getCollection = MeteorStore.getState()[collection];
if(!getCollection || !_.isEqual(getCollection[id], fields));{
if(
!getCollection ||
!getCollection[id] ||
!_.isEqual(getCollection[id], fields)
){
MeteorStore.dispatch({type: 'ADDED', collection, id, fields});
}
});
Expand Down
21 changes: 11 additions & 10 deletions example/RNApp/app/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@ import Meteor, { createContainer } from 'react-native-meteor';

// react-native-meteor-redux
import initMeteorRedux from 'react-native-meteor-redux';
import {AsyncStorage} from 'react-native';
import {persistStore, autoRehydrate} from 'redux-persist';
import { AsyncStorage } from 'react-native';
import { persistStore, autoRehydrate } from 'redux-persist';
// end react-native-meteor-redux

import LoggedOut from './layouts/LoggedOut';
Expand All @@ -16,22 +16,23 @@ Meteor.connect(settings.METEOR_URL);

// react-native-meteor-redux
const MeteorStore = initMeteorRedux(undefined, autoRehydrate());
persistStore(MeteorStore, {storage: AsyncStorage}, () => {
persistStore(MeteorStore, { storage: AsyncStorage }, () => {
MeteorStore.loaded();
});
setTimeout(()=> console.log(MeteorStore.getState()), 10000);
export {MeteorStore}
setTimeout(() => console.log(MeteorStore.getState()), 10000);
export { MeteorStore }
// end react-native-meteor-redux

const RNApp = (props) => {
const { status, user, loggingIn } = props;

// if (status.connected === false || loggingIn) {
// return <Loading />;
// } else if (user !== null) {
if (loggingIn) {
return <Loading />;
} else
if (user !== null) {
return <LoggedIn />;
// }
// return <LoggedOut />;
}
return <LoggedOut />;
};

RNApp.propTypes = {
Expand Down
3 changes: 2 additions & 1 deletion example/RNApp/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,8 @@
"private": true,
"scripts": {
"start": "node_modules/react-native/packager/packager.sh",
"lint": "eslint app/"
"lint": "eslint app/",
"meteor": "cd ../MeteorApp && Meteor && cd ../RNApp && react-native run-ios"
},
"dependencies": {
"@exponent/react-native-navigator": "^0.4.7",
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "react-native-meteor-redux",
"version": "1.1.12",
"version": "1.1.13",
"description": "Link react-native-meteor to redux",
"main": "connectMeteorRedux.js",
"scripts": {
Expand Down

0 comments on commit 0cc659a

Please sign in to comment.