
Security News
Attackers Are Hunting High-Impact Node.js Maintainers in a Coordinated Social Engineering Campaign
Multiple high-impact npm maintainers confirm they have been targeted in the same social engineering campaign that compromised Axios.
@devahmad/flex-state
Advanced tools
A library based on (ContextApi) for managing state in the application.
npm install @devahmad/flex-state
yarn add @devahmad/flex-state
import FlexState from "@devahmad/flex-state";
const createState = {
first: "Ahmad",
last: "Hassan",
info: { age: 28 },
};
const createDispatch = (data, tools, actions) => {
const { type, payload } = data; // return action as type and payload
const { update, state } = tools; // you can use thunk function from tools
/*
Update is a function that takes two parameters
1- value type: object => payload. like { age: 30 } - required
2- selector type: string => Where is the update. like "info"
This example will only update the age in 'info' key
*/
const setName = () => {
const fullName = payload.value?.toUpperCase();
update({ fullName });
};
switch (
type // action type
) {
case actions.setName: // actions type
return setName(); // you can write code like this to controle payload
case actions.logout:
return update(payload); // Or pass the payload directly
default:
break;
}
};
const flexState = new FlexState(createState, createDispatch);
export const MainProvider = flexState.Provider;
export const useMainSelector = flexState.useSelector;
export const useMainDispatch = flexState.useDispatch;
import { MainProvider } from "*path*/main-store";
// import Provider to wrap main component
...
export default function MyApp() {
return (<MainProvider>
{/* children */}
</MainProvider>);
}
import { useMainSelector } from "*path*/main-store";
...
const ExampleState = () => {
// you can use this useMainSelector at any component
const value = useMainSelector("first"); // return Ahmad
// Or useMainSelector((state) => state.first); // return Ahmad
// Or useMainSelector("full", (state) => `${state.first} ${state.last}`); // return Ahmad Hassan
// In all cases above, it will not be re-render, Except when changing the value of first
/*
useMainSelector is a function that takes two parameters
1- selector type: (string | function) - required
:string like "info.age" return 28
:function like (state) => state.info.age
2- fallback type: any => if value undefined return this value from fallback
:string like useMainSelector("status", "offline"); // return offline if status undefined
:array like useMainSelector("nums", ["one", "two"]); // return ["one", "two"] if nums undefined
:function like useMainSelector("full", (state) => state.first); // return Ahmad if full undefined
*/
return (<span>{value}</span>);
};
import { useMainDispatch } from "*path*/main-store";
...
const ExampleDispatch = () => {
// you can use this useMainDispatch at any component
const { dispatch } = useMainDispatch(); // return a function => dispatch
/*
dispatch is a function that takes two parameters
1- param1 type: (object | function | string) - required
:string like dispatch("setName", { value: e.target.value })
:object like dispatch({ age: e.target.value }, "info") return update function directly
:function like dispatch(async ({ update, add }) => {
// callback return two parameters update,state
try {
const res = await fetch(`https://api`);
const data = await res.json();
add({ age: 29 }, "info")
update({ last: data.last }); learn more about update => See above
} catch (e) {...}
})
2- param2 type: any => payload
*/
return (<input type="text"
onChange={(e) => dispatch("setName", { value: e.target.value })}
/>);
};
goto WhatsApp to learn more
FAQs
A library based on (ContextApi) for managing state in the application.
The npm package @devahmad/flex-state receives a total of 0 weekly downloads. As such, @devahmad/flex-state popularity was classified as not popular.
We found that @devahmad/flex-state 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
Multiple high-impact npm maintainers confirm they have been targeted in the same social engineering campaign that compromised Axios.

Security News
Axios compromise traced to social engineering, showing how attacks on maintainers can bypass controls and expose the broader software supply chain.

Security News
Node.js has paused its bug bounty program after funding ended, removing payouts for vulnerability reports but keeping its security process unchanged.