andres-kovalev / react-easy-flux

Easy and fast react binding for flux.
MIT License
0 stars 0 forks source link

Move storage configuration on Provider level #9

Open andres-kovalev opened 5 years ago

andres-kovalev commented 5 years ago

Initially it was debatable - when to configure storage (pass reducer and middlewares) when creating storage or putting context (Provider) into react tree. But now (especially after related #8) it's quite obvious - storage configuration should be moved to Provider level. It became more flexible and will provide ability to use the same context with different configurations. So, seems it should be implemented in redux-like way:

import createStorage from 'react-easy-flux';

const {
  configureStorage,
  Provider,
  useStorage
} = createStorage();

const storage = configureStorage(reducer, middleware);
andres-kovalev commented 5 years ago

Another option is:

import createStorage from 'react-easy-flux';

const {
  configureProvider,
  useStorage
} = createStorage();

const Provider = configureProvider(reducer, middlewares);
andres-kovalev commented 5 years ago

Less preferable option:

const {
  Provider,
  useStorage
} = createStorage();

const App = () => (
  <Provider reducer={ reducer } middlewares={ middlewares } storage={ storage }>
    { content }
  </Provider>
);
andres-kovalev commented 5 years ago

Another option:

const configureStorage = createStorage();

const {
  Provider,
  useStorage
} = configureStorage(reducer, middlewares);
andres-kovalev commented 5 years ago

Looks like 1st option is a winner