
Security News
Socket Releases Free Certified Patches for Critical vm2 Sandbox Escape
A critical vm2 sandbox escape can allow untrusted JavaScript to break isolation and execute commands on the host Node.js process.
@calvear/react-redux
Advanced tools
Preconfigured Redux store initializer with Redux Saga, Redux Logger and Reselect for React SPA applications.
React library for eases Redux initialization for React SPA application. Is preconfigured and included helpful libraries as redux-logger and reselect.
βββ README.md
βββ LICENCE.md
βββ CHANGELOG.md
βββ .vscode/ # vscode shared development config
βββ src/
βΒ Β βββ effects/ # extra saga effects
βΒ Β βββ hooks/ # extra redux hooks
βΒ Β βββ reselect/ # reselect export bypass
βΒ Β βββ utils/ # action types utils
βΒ Β βββ middleware.js # middleware loader
βΒ Β βββ store.js # createStore
βΒ Β βββ index.js
βββ package.json
βββ jsconfig.js
βββ .babelrc
βββ .eslintrc.json
βββ .prettierrc.json
Should be initialized with StoreProvider on App.jsx like:
import { StoreProvider } from '@calvear/react-redux';
import store from 'store';
export default function App() {
return (
<StoreProvider store={store}>
<h1>Welcome to My App!</h1>
</RouterProvider>
);
}
So, you can create your first reducer, for example in store folder:
βββ ...
βββ store/
βΒ Β βββ sample/
βΒ Β βΒ Β β βββ sample.partition.js # contains actions types and partition/store states
βΒ Β βΒ Β β βββ sample.reducer.js # reducer
βΒ Β βΒ Β β βββ sample.saga.js # saga middleware
βΒ Β βββ index.js # exports default store
βββ App.jsx
βββ index.js
Define your partition definition, containing partition key and actions types in sample.partition.js:
export default {
// partition key
Key: 'SAMPLE',
// action types
Type: {
EXEC: 'EXEC',
COMMIT: 'COMMIT',
ROLLBACK: 'ROLLBACK',
},
// partition states
State: {
PREPARING: 'PREPARING',
EXECUTING: 'EXECUTING',
READY: 'READY',
FAILED: 'FAILED',
},
};
Define your reducer in sample.reducer.js:
import SamplePartition from './sample.partition';
export default function SampleReducer(store = {}, action) {
const { type, payload } = action;
switch (type) {
// executes the action.
case SamplePartition.Type.EXEC:
return {
...store,
state: SamplePartition.State.EXECUTING,
data: payload,
};
// action is successful.
case SamplePartition.Type.COMMIT:
return {
...store,
state: SamplePartition.State.READY,
};
// action was finished with errors.
case SamplePartition.Type.ROLLBACK:
return {
...store,
state: SamplePartition.State.FAILED,
error: payload,
};
// default doesn't changes the store,
// so, components won't re-renders.
default:
return store;
}
}
Finally (optional) your middleware saga in sample.saga.js:
import { all, call, dispatch, takeLatest } from '@calvear/react-redux/effects';
import SamplePartition from './sample.partition';
import Service from 'adapters/service';
function* exec({ payload }) {
try {
const data = yield call(Service.GetData);
// Success action.
yield dispatch(SamplePartition.Type.COMMIT, data);
} catch (e) {
yield dispatch(SamplePartition.Type.ROLLBACK, {
stacktrace: e,
message: 'Operation cannot be completed',
});
}
}
export default function* run() {
yield all([
// use all only if exists two or more listeners.
takeLatest(SamplePartition.Type.EXEC, exec),
]);
}
Finally, your store/index.js file should looks like:
import { createStore } from '@calvear/react-redux';
import { SamplePartition, SampleReducer, SampleSaga } from './sample';
const reducers = {
[SamplePartition.Key]: SampleReducer,
};
const sagas = [SampleSaga()];
export default createStore({ reducers, sagas, true });
Library has custom hooks for eases partition handling.
import { usePartition } from '@calvear/react-redux/hooks';
import { SamplePartition } from 'store/sample';
export default function MainPage()
{
const { state, data, error } = usePartition(SamplePartition);
...
}
import { useEffect } from 'react';
import { useActionDispatch } from '@calvear/react-redux/hooks';
import { SamplePartition } from 'store/sample';
export default function MainPage()
{
const dispatchSampleExec = useActionDispatch(SamplePartition.Type.EXEC);
useEffect(() =>
{
dispatchSampleExec({ someProp: 'hello world' });
}, []);
...
}
Also, exports every hook from react-redux lib.
import { useSelector } from '@calvear/react-redux/hooks';
import { SamplePartition } from 'store/sample';
export default function MainPage()
{
const state = useSelector(({ [SamplePartition.Key]: state }) => state);
// in this example, will returns same that usePartition(...)
...
}
import { useEffect } from 'react';
import { useDispatch } from '@calvear/react-redux/hooks';
import { SamplePartition } from 'store/sample';
export default function MainPage()
{
const dispatch = useDispatch();
useEffect(() =>
{
dispatch({
type: SamplePartition.Type.EXEC,
payload: { someProp: 'hello world' }
});
// in this example, will behaves like useActionDispatch(...)
}, []);
...
}
import { useStore } from '@calvear/react-redux/hooks';
export default function MainPage()
{
const store = useStore();
const state = store.getState();
...
}
Library integrates and exports reselect lib.
import { createPartitionSelector } from '@calvear/react-redux';
import { useSelector } from '@calvear/react-redux/hooks';
import { createSelector } from '@calvear/react-redux/reselect';
import { SamplePartition } from 'store/sample';
const sampleSelector = createPartitionSelector(SamplePartition);
const sampleDataSelector = createSelector(
sampleSelector,
sample => sample.data
)
export default function MainPage()
{
const data = useSelector(sampleDataSelector);
...
}
Library has custom redux-saga effects.
import { dispatch } from '@calvear/react-redux/effects';
import { SamplePartition } from 'store/sample';
function* exec({ payload })
{
// dispatches COMMIT action
yield dispatch(
SamplePartition.Type.COMMIT,
payload
);
}
...
import { selectPartition } from '@calvear/react-redux/effects';
import { SamplePartition } from 'store/sample';
function* exec()
{
// extracts sample state from store
const { state, data, error } = yield selectPartition(SamplePartition);
}
...
import { takeAny } from '@calvear/react-redux/effects';
import { SamplePartition } from 'store/sample';
function* exec()
{
// waits for any EXEC or COMMIT action,
// intercepting two of these dispatches
const [
firstResult,
secondResult
] = yield takeAny([
SamplePartition.Type.EXEC,
SamplePartition.Type.COMMIT
], 2);
}
...
Redux doesn't handles action types collision for reducers, so, for example if we has two partitions/reducers with same actions (EXEC, COMMIT), will conflicts dispatching any of these.
This library provides of a utility for prefix partition key to every action type.
import { packagePartitionHandler } from '@calvear/react-redux/utils';
let SamplePartition = {
// partition key
Key: 'SAMPLE',
// action types
Type: {
EXEC: 'EXEC',
COMMIT: 'COMMIT',
ROLLBACK: 'ROLLBACK',
},
...
};
// prefixes action types with partition key
export default packagePartitionHandler(SamplePartition);
Project uses ESLint, for code formatting and code styling normalizing.
For correct interpretation of linters, is recommended to use Visual Studio Code as IDE and install the plugins in .vscode folder at 'extensions.json', as well as use the config provided in 'settings.json'
For last changes see CHANGELOG.md file for details.
This project is licensed under the MIT License - see LICENSE.md file for details.
β¨ by Alvear Candia, Cristopher Alejandro
FAQs
Preconfigured Redux store initializer with Redux Saga, Redux Logger and Reselect for React SPA applications.
The npm package @calvear/react-redux receives a total of 9 weekly downloads. As such, @calvear/react-redux popularity was classified as not popular.
We found that @calvear/react-redux demonstrated a not healthy version release cadence and project activity because the last version was released a year ago.Β It has 1 open source maintainer collaborating on the project.
Did you know?

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Security News
A critical vm2 sandbox escape can allow untrusted JavaScript to break isolation and execute commands on the host Node.js process.

Research
Five malicious NuGet packages impersonate Chinese .NET libraries to deploy a stealer targeting browser credentials, crypto wallets, SSH keys, and local files.

Security News
pnpm 11 turns on a 1-day Minimum Release Age and blocks exotic subdeps by default, adding safeguards against fast-moving supply chain attacks.