0.1.0 • Published 7 years ago
spreadux v0.1.0
spreadux
Helps to avoid nightmares like this:
const entities = {
...this.state.entities,
ws: {
...this.state.entities.users,
[id]: {
...this.state.entities.users[id],
isChanging: isChanging
}
}
}
How it works
Consider a typical normalized data.
const state = {
result: [1],
entities: {
subjects: {
1: {
id: 1,
title: 'Example',
path: '/example',
isActive: true
}
}
}
};
We want easily change any fields in any subject. So, spread helper
will be:
const subjectSpread = spreadux(['entities', 'subjects', '[id]']);
Now, we can apply that helper to our normalized data:
const newState = subjectSpread(state, { isActive: false }, 1);
Result:
{
result: [1],
entities: {
subjects: {
1: {
id: 1,
title: 'Example',
path: '/example',
isActive: false
}
}
}
}
Dependencies
None.