
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.
Easy, lightweight and powerful state management tool designed as redux or mobX replacement.
npm i -s mega-box
megaBox(initialState: Object, plugins?: { [name]: (state: Object) => unknown })
Start with creating sate:
const initailState = { userName: 'Jack John', userId: 123 };
const appState = megaBox(initialState);
Plugins can be passed by second argument. Each plugin is function which get state as single argument.
const onUserIdChange = state => (cb: () => void) => {
return state.subscribe(cb, ['userId']);
}
const appState = megaBox(initialState, { onUserIdChange });
appState.onUserIdChange(() => {
console.log('UserId is changed and this handled by plugin');
});
To read value just get it from state as from object:
const user = appState.user;
// or
const { user} = appState;
To write single value set it as in object:
appState.user = ‘John Smith’;
To update few fields in state call appState.put:
appState.put({ user: 'John Smith', userId: 987 });
appState.subscribe(callback, filter?: string[] | false)
Avoid to writing more than one value by setting them in state. Use
putinstead.
Every single write in state will call callback separately.
callback - required. Will be called immediately after subscription and when state changes. Callback receive actual state as first argument and boolean as second argument. Boolean specify if it called first time (true) or after something change (false).
filter - optional. Used to describe which state keys should be changed to invoke callback. Possible values:
false - will disable filter at all and callback will be called every updatestring[] - specify keys to track changesmegaBox automaticaly solve when call callbackMegaBox remember which values used in first subscriber callback call and optimize performance by calling callback only when those values are changed.
Use state distructurization and read required values at the start of callback function.
Avoid getting values in conditions, some conditions can be scipped at the first call and lead to bugs when listener don’t call when value is changed.
To avoid callback execution when some values changed use appState.<key> instead of getting value from listener params.
// Invoke callback every time when user is changed
appState.subscribe(({ user }) => {
// Get value when the user changed but changing userId not invoke callback
Const { userId } = appState;
});
FAQs
Easy, lightweight and powerful state management tool
We found that mega-box demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 0 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
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.