Research
Security News
Malicious npm Package Targets Solana Developers and Hijacks Funds
A malicious npm package targets Solana developers, rerouting funds in 2% of transactions to a hardcoded address.
immutable-functions
Advanced tools
A simple, easy, straight forward approach to update immutable data.
A simple, easy, straight forward approach to update immutable data.
$ yarn add immutable-functions
or
$ npm install -s immutable-functions
import _i from 'immutable-functions';
import { CREATE, UPDATE, REMOVE } from '../actions/collection';
export default (state = [], action) => {
switch (action.type) {
case CREATE:
return _i.create(state, action.obj);
case UPDATE:
return _i.update(state, action.obj.id, action.obj);
case REMOVE:
return _i.destroy(state, action.obj.id);
default:
return state;
}
};
import React, { PureComponent } from 'react';
import { View, Text } from 'react-native';
import { connect } from 'react-redux';
import _i from 'immutable-functions';
class YourComponent extends PureComponent {
render() {
// Get the item with id === 5
const item = _i.find(this.props.data, 5)
// item
// {
// id: 5,
// name: Jerry,
// email: jerry@gmail.com
// }
return (
<View>
<Text>Name: {item.name}</Text>
<Text>Email: {item.email}</Text>
</View>
);
}
}
// Here are the properties of the store this component uses
const mapStoreToProps = store => ({
data: store.yourReducer
});
// This is how we connect the store to our component
export default connect(mapStoreToProps)(YourComponent);
_i.create(state, data)
Creates an object if it does not already exist (by id
) in the array.
_i.update(state, id, data)
Updates an object if it exists (by id
) in the array, if it does not exist, it will create it.
_i.destroy(state, id)
Destroys an object if it exists (by id
) in the array.
_i.merge(state, array[, deep])
Merges an object or array of objects (unique by id
) with the current state.
id
_i.find(state, id)
Find an object if it exists (by id
) in the array. Useful in components when accessing the data.
_i.findByProp(state, prop, id)
Find an object if it exists by a property provided in the array. Useful in components when accessing the data.
_i.findByProp(state, 'LoanId', '1234456');
_i.updateByProp(state, prop, id, data)
Updates an object if it exists by an identifier property provided in the array, if it does not exist, it will create it.
_i.updateByProp(state, 'LoanId', action.obj.LoanId, action.obj);
_i.destroyByProp(state, prop, id)
Destroy an object if it exists by an identifier property provided in the array.
_i.destroyByProp(state, 'LoanId', action.obj.LoanId);
_i.mergeByProp(state, array, prop[, deep])
Merges an object or array of objects (unique by prop) with the current state.
FAQs
A simple, easy, straight forward approach to update immutable data.
The npm package immutable-functions receives a total of 242 weekly downloads. As such, immutable-functions popularity was classified as not popular.
We found that immutable-functions 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.
Research
Security News
A malicious npm package targets Solana developers, rerouting funds in 2% of transactions to a hardcoded address.
Security News
Research
Socket researchers have discovered malicious npm packages targeting crypto developers, stealing credentials and wallet data using spyware delivered through typosquats of popular cryptographic libraries.
Security News
Socket's package search now displays weekly downloads for npm packages, helping developers quickly assess popularity and make more informed decisions.