Security News
Fluent Assertions Faces Backlash After Abandoning Open Source Licensing
Fluent Assertions is facing backlash after dropping the Apache license for a commercial model, leaving users blindsided and questioning contributor rights.
react-redux-procedures
Advanced tools
A wrapper for react-redux's connect to allow execution of multiple actions in a single procedure
A wrapper for react-redux's connect to allow execution of multiple actions in a single procedure
The procedures are mapped into the three arguments of the basic connect method of react-redux, so that you get props of dispatchable "procedures". Procedures only take arguments and are already stateful and able to dispatch actions. This is really useful if you have actions that are always executed after or next to each other, or if you use actions that depend a lot on your apps State.
createProcedure
// procedure file
import { createProcedure } from "react-redux-procedures";
type State = { someStateVal: any }; // to be filled in, if working with flow
type Params = {};
export const procedure = createProcedure(
dispatch => ({ someStateVal }: State) => ({ }: Params): Promise<any> => {
// this is where the magic happens.
// you can dispatch actions, they may be dependent on each other.
dispatch(someAction());
dispatch(someOtherAction);
return dispatch(somePromiseAction()).then(() => 'Yay!'):
},
(state: AppState) => ({
someStateVal: state.val
})
);
IMPORTANT: Don't forget that the state is already bound when you call the procedure. this means it won't change after dispatching actions internally and may have already changed when you reach a promise result. Procedures should only be dependent on the state at the begin of the procedure.
connectProcedures(
mapProceduresToProps: { [key]: Procedure },
mapStateToProps?,
mapDispatchToProps?,
mergeProps?,
options?
)
The optional Arguments are just your standard connect arguments that will get applied by connectProcedures so you don't have to wrap a component in connectProcedures and a standard connect as well.
// component file
import { connectProcedures, type ProcedureDispatcher } from 'react-redux-procedures';
import { someImportedProcedure } from 'somewhere';
type Props = {
someProc: ProcedureDispatcher<typeof someImportedProcedure>,
};
const Component = ({ someProc }: Props) =>
<span onClick={() => someProc()}> I dispatch a procedure! </span>;
const mapProceduresToProps = {
someProc: someImportedProcedure,
};
export default connectProcedures(mapProceduresToProps)(Component);
prepareProcedure(Procedure, Dispatch, State)
// file where you need to call a procedure manually
import { prepareProcedure } from "react-redux-procedures";
import { someImportedProcedure } from "somewhere";
const prepared = prepareProcedure(someImportedProcedure, reduxStore.dispatch, reduxStore.getState());
prepared(/* params */);
type Procedure<State, Params, Result, AppState> = {
(dispatch: Dispatch<any>): State => Params => Result,
mapStateToProcState: AppState => S,
};
So, a procedure is something that
mapStateToProcState
which takes the AppState and returns the procedure-specific state.There is also a stateless variant, seen below.
type StatelessProcedure<Params, Result> = {
(dispatch: Dispatch<any>): () => Params => Result,
};
As the name suggests, this is just a helper type that takes the Params => Result
bit of a given procedure. The type is
simplified to not confuse you with flow weirdness, just know that Params and Result are inferred from the given
Procedure.
type ProcedureDispatcher<Procedure|StatelessProcedure> = Params => Result;
FAQs
A wrapper for react-redux's connect to allow execution of multiple actions in a single procedure
We found that react-redux-procedures demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 2 open source maintainers 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
Fluent Assertions is facing backlash after dropping the Apache license for a commercial model, leaving users blindsided and questioning contributor rights.
Research
Security News
Socket researchers uncover the risks of a malicious Python package targeting Discord developers.
Security News
The UK is proposing a bold ban on ransomware payments by public entities to disrupt cybercrime, protect critical services, and lead global cybersecurity efforts.