Skip to content

Commit

Permalink
removed React.context behavior
Browse files Browse the repository at this point in the history
  • Loading branch information
chrisdugne committed Feb 7, 2021
1 parent 1425a61 commit 5986a67
Show file tree
Hide file tree
Showing 3 changed files with 45 additions and 67 deletions.
66 changes: 0 additions & 66 deletions src/hookstores-provider.js

This file was deleted.

2 changes: 1 addition & 1 deletion src/index.js
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
export {default as connectStore} from './connect-store.js';
export {Hookstores, useHookstores} from './hookstores-provider.js';
export {createStores, useStores} from './stores.js';
44 changes: 44 additions & 0 deletions src/stores.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
// -----------------------------------------------------------------------------

import createStore from './create-store';

// -----------------------------------------------------------------------------

let stores;

// -----------------------------------------------------------------------------

const createStores = descriptions => {
console.log('☢️ [hookstores] creating Hookstores...', descriptions);
stores = Object.keys(descriptions).reduce((acc, storeKey) => {
console.log(`☢️ [hookstores] registering ${storeKey}`);
const store = createStore(storeKey, descriptions[storeKey]);

return {
...acc,
[storeKey]: store
};
}, {});
};

// -----------------------------------------------------------------------------

const dispatch = action => {
console.log('📡 [hookstores] dispatching', action);
Object.keys(stores).forEach(storeKey => {
stores[storeKey].onDispatch(action);
});
};

// -----------------------------------------------------------------------------

const useStores = () => {
// for debugging purposes - *will be removed* 🧐
window.stores = stores;

return {...stores, dispatch};
};

// -----------------------------------------------------------------------------

export {createStores, useStores};

0 comments on commit 5986a67

Please sign in to comment.