Skip to content

Commit 0a8d3ba

Browse files
committed
Chore: Moved Bundling From Tsc To Rollup
1 parent fbd6cac commit 0a8d3ba

File tree

124 files changed

+84801
-74
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

124 files changed

+84801
-74
lines changed

.rollup.cache/home/husseinkizz/Projects/react-hands/dist/src/index.js

+56
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

.rollup.cache/home/husseinkizz/Projects/react-hands/dist/src/index.js.map

+1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

dist/react-hands.js renamed to .rollup.cache/home/husseinkizz/Projects/react-hands/dist/src/react-hands.js

+2-29
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

.rollup.cache/home/husseinkizz/Projects/react-hands/dist/src/react-hands.js.map

+1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

.rollup.cache/home/husseinkizz/Projects/react-hands/dist/tsconfig.tsbuildinfo

+1
Large diffs are not rendered by default.

CHANGELOG.md

+3-1
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,8 @@ React's Own Hands Touching State The Easiest Way!
2525
- Done: Test package installation and usage locally before publishing to npm!
2626
- Done: published first beta version, via Js Kampala Open Source!
2727

28-
## React Hands, 31-Mar-2023 (v1.0.1)
28+
## React Hands, 31-Mar-2023 (v1.0.4)
2929

3030
- Fixing: NPM error on package install!
31+
- Boost: Migrate from tsc to rollup
32+
- Done: Configure And Setup Rollup Bundler

dist/index.js

+29-33
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

dist/index.js.map

+1-1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

dist/index.mjs

+58
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
import * as React from 'react';
2+
3+
// React Hands
4+
const { createContext, useContext, useReducer, useMemo, useCallback } = React;
5+
const StoreContext = createContext(undefined);
6+
function reactState(initialState = {}, actions = {}, middlewares = []) {
7+
function reducer(state, action) {
8+
const handler = actions[action.type];
9+
if (handler) {
10+
return handler(state, action);
11+
}
12+
else {
13+
// handle error then return state as is -- line 1.0
14+
console.log(`Bad Hands: Your probably passed a different reference to dispatch, "${action.type}" should match the same state name referenced in state!`);
15+
return state;
16+
}
17+
}
18+
function applyMiddlewares(middlewares, store) {
19+
const middlewareAPI = {
20+
state: store.state,
21+
dispatch: (action) => newDispatch(action),
22+
};
23+
const functionsChainArray = middlewares.map((middleware) => middleware(middlewareAPI));
24+
const newDispatch = compose(functionsChainArray)(store.dispatch);
25+
return newDispatch;
26+
}
27+
function compose(funcs) {
28+
return useCallback(function composed(arg) {
29+
let result = arg;
30+
for (let i = funcs.length - 1; i >= 0; i--) {
31+
result = funcs[i](result);
32+
}
33+
return result;
34+
}, [funcs]);
35+
}
36+
const StoreProvider = ({ children, }) => {
37+
const [state, dispatch] = useReducer(reducer, initialState);
38+
const enhancedDispatch = applyMiddlewares(middlewares, {
39+
state,
40+
dispatch,
41+
});
42+
const memorizedValue = useMemo(() => ({ state, dispatch: enhancedDispatch }), [state]);
43+
return (React.createElement(StoreContext.Provider, { value: memorizedValue }, children));
44+
};
45+
function useStore() {
46+
const context = useContext(StoreContext);
47+
// tell user to wrap their app in store provider
48+
if (context === undefined) {
49+
throw new Error('Bad Hands: Your top level component or app must be wrapped within the StoreProvider!');
50+
}
51+
const { state, dispatch } = context;
52+
return [state, dispatch];
53+
}
54+
return { StoreProvider, useStore };
55+
}
56+
57+
export { reactState };
58+
//# sourceMappingURL=index.mjs.map

0 commit comments

Comments
 (0)