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

Differences in the inline and the normal way #18

Open
Buom01 opened this issue Jul 9, 2018 · 1 comment
Open

Differences in the inline and the normal way #18

Buom01 opened this issue Jul 9, 2018 · 1 comment
Labels
question Further information is requested

Comments

@Buom01
Copy link

Buom01 commented Jul 9, 2018

Hi,
I expect a lot of bug with stockroom (or maybe I using it wrong ?)

I extract a little part of my webapp to inspect it, but I encounter an (other) probleme.
To reproduce the bugs : https://github.com/Buom01/stockroom-bug-demo (created with preact-cli)

the subscribe method

In this case, the "normal" usage, the store have not got the subscribe method defined:

import createStore from 'stockroom/inline'
import StoreWorker from 'workerize-loader!./worker.store'
let store = createStore(new StoreWorker())
console.log(store.subscribe) // undefined, WHY ?

While in the "inline" usage, the method subscribe is defined normally:

import createStore from 'stockroom/inline'
let store = createStore(require('./worker.store').default)
console.log(store.subscribe) // defined as a function

A probleme of shared store in the "inline" mod

Sorry because I can not totally reproduce the bug that I want to resolve due to the probleme with the subscribe method.
The probleme can be showed partially in the demo provided: I add only one document to each store, but in the inline mod, the store are mixed and finally they share their data. Then, they have both the same data while they should be isolated like in the worker mod. (Confirmed in my local project)

Tested in both Chromium(Version 67.0.3396.79 (Build de développement) Fedora Project (64 bits)) and Firefox(61.0) (latest)

@developit
Copy link
Owner

developit commented Jul 26, 2018

Hello,

The usage here is incorrect. stockroom/inline accepts an instance of Stockroom (as returned by stockroom/worker), but you're passing it a worker. So it's not a bug, but I think the documentation could definitely be more clear, and perhaps some examples would help.

See below:

store.js: (doesn't care if it's in a worker or not)

import createStore from 'stockroom/worker';
const store = createStore({ count: 0 });
store.registerActions({
  increment: state => ({ count: state.count+1 })
});
export default store;

worker usage with stockroom:

import createWorkerStore from 'stockroom';
import StoreWorker from 'workerize-loader!./store';

const store = createWorkerStore(new StoreWorker());
store.subscribe(console.log);
store.action('increment')();

inline (no worker) usage with stockroom/inline:

import createInlineStore from 'stockroom/inline';
import store from './store';

const store = createInlineStore(store);
store.subscribe(console.log);
store.action('increment')();

@developit developit added the question Further information is requested label Jul 26, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
question Further information is requested
Projects
None yet
Development

No branches or pull requests

2 participants