Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add increment() and decrement() #17

Open
cwayfinder opened this issue Oct 27, 2017 · 2 comments
Open

Add increment() and decrement() #17

cwayfinder opened this issue Oct 27, 2017 · 2 comments

Comments

@cwayfinder
Copy link

This is a feature request. There is toggle() for a boolean value and I would like to have similar stuff for numbers.

Example: the following code

const deadCount = state.players[playerIndex].commander.deadCount + 1;
state = dotProp.merge(state, `players.${playerIndex}.commander`, { deadCount });

could be replaced with

state = dotProp.increment(state, `players.${playerIndex}.commander.deadCount`);

I used merge instead of set because the property deadCount might be not initialized. In this case, we can treat it as 0.

@Flamenco
Copy link
Contributor

How about an optional parameter for the delta, with default of 1

state = dotProp.increment(state, `players.${playerIndex}.commander.deadCount`); // default is 1
state = dotProp.increment(state, `players.${playerIndex}.commander.deadCount`, 10);

@cwayfinder
Copy link
Author

Then the naming should be increase and decrease.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants