Research
Security News
Threat Actor Exposes Playbook for Exploiting npm to Build Blockchain-Powered Botnets
A threat actor's playbook for exploiting the npm ecosystem was exposed on the dark web, detailing how to build a blockchain-powered botnet.
@meniga/immutable
Advanced tools
The purpose of these helpers is to make state changes in object more straight forward and more optimized for React rendering with shouldComponent update. The "change" methods always return a new reference if something has changed. But the references of things not changed stay the same.
There was/is a problem with assign methods used now that can cause a mutation of the object and keep the reference of arrays/objects. That will cause React to think nothing has changed
const arr1 = [1]
const arr2 = arr[0] = 2
const state1 = assign({ items: arr })
const state2 = assign({ items: arr })
// state1.items === state2.items => true
This is the way it works but as we want the immutable way to optimize the rendering it is too easy to mutate. There are a lot of logic in the reducers doing simple things like updating an item in array or adding data to an item in array etc...
There are quite a few helpers, but you will probably only use a few of them often. The methods are curried so you can compose multiple changes in one go with the compose
method or composeState
method from reducer callback (more later in this readme)
These methods are really simple and only wrap some lodash/fp methods to create a consistent way and naming conventions. It is easier to pull all data chasing from one lib than pulling in some from lodash, lodash/fp, utils etc...
This is good to change state inside a nested state. For arrays you would use findIndexIn
.
const state = {
isFetched: true,
items: [
{ id: 1, title: 'Title 1' },
{ id: 2, title: 'Title 2' },
]
}
// Notice the (state) at the end. The methods return functions
return updateIn(['items', findIndexIn('items', { id: 2 })], { title: 'Change title' })(state)
/*
{
isFetched: true,
items: [
{ id: 1, title: 'Title 1' },
{ id: 2, title: 'Changed title' },
]
}
*/
// Only items has changed
// => this.state.items === nextState.items => false
// => this.state.isFetched === nextState.isFetched => true
TODO
- allow predicate as 3rd parameter and that would find the index if needed
The other benefit of using the "fp" version of lodash methods is that it is easy to make the helpers compassable. That way you can return multiple state changes in one go
return compose(
updateIn(['items', 13, 'rules', 2], { active: false }),
mergeIn(['accounts', 3], { title: 'Account', meta: { show: false } }),
removeIn([settings.totalAmount])
)(state)
You see that we give most of these methods the state (state). I have added the compose
method as composeState
in the reducer action callback. That one already has the state so no need to provide it
SUCCESS: ( state, { composeState } ) {
return composeState(
updateIn(),
// ...
)
}
FAQs
## Immutable state changes
The npm package @meniga/immutable receives a total of 122 weekly downloads. As such, @meniga/immutable popularity was classified as not popular.
We found that @meniga/immutable demonstrated a healthy version release cadence and project activity because the last version was released less than 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.
Research
Security News
A threat actor's playbook for exploiting the npm ecosystem was exposed on the dark web, detailing how to build a blockchain-powered botnet.
Security News
NVD’s backlog surpasses 20,000 CVEs as analysis slows and NIST announces new system updates to address ongoing delays.
Security News
Research
A malicious npm package disguised as a WhatsApp client is exploiting authentication flows with a remote kill switch to exfiltrate data and destroy files.