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

No Actions when Store is composed with redux-replicate. #93

Closed
derpoho opened this issue Apr 17, 2016 · 16 comments
Closed

No Actions when Store is composed with redux-replicate. #93

derpoho opened this issue Apr 17, 2016 · 16 comments

Comments

@derpoho
Copy link

derpoho commented Apr 17, 2016

Hey,

great work on this tool, but i am experiencing problems when the store is composed with redux-replicate before created, i don`t know where the root of the problem is, the only thin i know is: I deactivate the Replication, all actions are displayed correctly. I activate it the DevTools just get the init action and no more after that. The State shown by the init function is still updated though.

Even if is use the suggested implementation from redux-replicate:

import { createStore, combineReducers, compose } from 'redux';
import replicate from 'redux-replicate';
import localforage from 'redux-replicate-localforage';
import reducers from './reducers';

const initialState = {
  wow: 'such storage',
  very: 'cool'
};

const key = 'superCoolStorageUnit';
const replication = replicate(key, true, localforage);
const create = compose(replication)(createStore);
const store = create(combineReducers(reducers), initialState, DEVTOOLS HERE);

Can somebody confirm this?

@zalmoxisus
Copy link
Owner

zalmoxisus commented Apr 17, 2016

Hey @Clubdesign,

Not sure if that is the reason, but you're mixing old redux api with the new one.

So if you use an old version of redux, it will be:

const create = compose(replication, window.devToolsExtension())(createStore);
const store = create(combineReducers(reducers), initialState);

Or for the new one:

const enhancer = compose(replication, window.devToolsExtension());
const store = createStore(combineReducers(reducers), initialState, enhancer);

@derpoho
Copy link
Author

derpoho commented Apr 17, 2016

Hey @zalmoxisus ,

thanks for the suggest, but it still isn`t working, the above example is directly from redux-replicate, in my code i am doing it like this:

export default function configureStore( initialState ) {

  const replication = replicate(STORAGE_KEY, STORAGE_STATE_KEYS, localforage, initialState);
  const create = compose(replication, window.devToolsExtension)(createStore);
  const logger = createLogger(LOGGER_OPTIONS);

  const store_middleware = applyMiddleware( thunk, logger, routerMiddleware(browserHistory) );
  const store_enhancer = compose(store_middleware, replication, window.devToolsExtension() );

  const store = createStore(
    rootReducer,
    initialState,
    store_enhancer
  );

  return store
}

@zalmoxisus
Copy link
Owner

That seems right. Don't you get any warnings/errors in the console? Does it work with vanilla Redux Devtools?

@derpoho
Copy link
Author

derpoho commented Apr 17, 2016

Yes it works with Vanilla, and no Errors or anything elese, just the @init State. As said, the State keeps updating, but the dispatched action are not shown, see here:

http://d.pr/i/1811t/15oqmzJQ

@zalmoxisus
Copy link
Owner

zalmoxisus commented Apr 17, 2016

I guess you mean redux logger middleware. By vanilla Redux DevTools I mean https://github.com/gaearon/redux-devtools. Please try to implement that instead of the extension, if it will steel not work, then more likely the problem is somewhere in redux-replicate. Usually, the described behaviour appears when the state is mutated.

@derpoho
Copy link
Author

derpoho commented Apr 17, 2016

Nono, i mean the normal tools, i had them running correctly before i tried the extension. Everything is working.
Just as a hint: When i remove the replication, it is working normal and correctly, so maybe it`s something within redux-replicate what does not comply with the extension?

@zalmoxisus
Copy link
Owner

That's interesting. I will try it.

@derpoho
Copy link
Author

derpoho commented Apr 17, 2016

See: http://d.pr/i/13lXR/4PboxiX3

Is just replace everything back to Vanilla DevTools:

export default function configureStore( initialState ) {

  const replication = replicate(STORAGE_KEY, STORAGE_STATE_KEYS, localforage, initialState);

  const store_middleware = applyMiddleware( thunk, createLogger(LOGGER_OPTIONS), routerMiddleware(browserHistory) );
  const store_enhancer = compose(store_middleware, replication, DevTools.instrument() );

  const store = createStore(
    rootReducer,
    initialState,
    store_enhancer
  );

  return store
}

@zalmoxisus
Copy link
Owner

zalmoxisus commented Apr 17, 2016

Could you please try to add

store.subscribe(() => { console.log(store.getState()); });

and check if you get the new value every time? If not then the problem should be investigated inside redux-replicate. Though it would be strange that it works with react-redux.

@derpoho
Copy link
Author

derpoho commented Apr 17, 2016

Yes, the state is logged with every action when subscribed.

@zalmoxisus
Copy link
Owner

Thanks for the details. Yes, due to the fact that it replaces the reducer the extension don't get the new store. I'll investigate it.

@derpoho
Copy link
Author

derpoho commented Apr 17, 2016

Ok, thanks @zalmoxisus !

@derpoho
Copy link
Author

derpoho commented Apr 17, 2016

Sorry @zalmoxisus , i tried that already, but then the replication fails completly. But i can confirm, that the DevTools Work with this setup. But it doesn't help as the replcation is failing ;)

zalmoxisus added a commit that referenced this issue Apr 18, 2016
@zalmoxisus
Copy link
Owner

zalmoxisus commented Apr 18, 2016

Well, the problem is that redux-replicate creates the store twice (first time in L180 and the second one in L133). Looks odd, but anyway fixed in 97eb9d3.

To get it work, you can install v1.0.0.22 or wait few hours till chrome autoupdates the extension. If something is still wrong, feel free to reopen the issue.

@derpoho
Copy link
Author

derpoho commented Apr 18, 2016

Thx @zalmoxisus, will try it

@derpoho
Copy link
Author

derpoho commented Apr 18, 2016

Can confirm it works with the current latest version @zalmoxisus.
Thanks!

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

2 participants