dot-prop-immutable icon indicating copy to clipboard operation
dot-prop-immutable copied to clipboard

Add increment() and decrement()

Open cwayfinder opened this issue 7 years ago • 2 comments

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.

cwayfinder avatar Oct 27 '17 03:10 cwayfinder

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);

Flamenco avatar Oct 27 '17 13:10 Flamenco

Then the naming should be increase and decrease.

cwayfinder avatar Oct 27 '17 19:10 cwayfinder