0.1.0 • Published 7 years ago

spreadux v0.1.0

Weekly downloads
3
License
MIT
Repository
github
Last release
7 years ago

Build Status

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.

0.1.0

7 years ago

0.0.4

7 years ago

0.0.3

7 years ago

0.0.2

7 years ago

0.0.1

7 years ago