-
Notifications
You must be signed in to change notification settings - Fork 57
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
fix: adjust increment api and remove add from NumberSignal #2704
Merged
platosha
merged 11 commits into
main
from
taefi/fix-increment-and-remove-add-from-numbersignal
Sep 11, 2024
Merged
Changes from all commits
Commits
Show all changes
11 commits
Select commit
Hold shift + click to select a range
42dd10e
fix: adjust increment api and remove add from NumberSignal.ts
taefi ab6419d
remove unnecessary imports and chai-like usage
taefi fea38ba
formatter:format
taefi 4233c76
set the value locally when incrementBy is called
taefi d859ac6
address sonar warnings
taefi e81d630
Merge branch 'main' into taefi/fix-increment-and-remove-add-from-numb…
taefi 716ce3e
Merge branch 'main' into taefi/fix-increment-and-remove-add-from-numb…
taefi 5eee03e
Merge branch 'main' into taefi/fix-increment-and-remove-add-from-numb…
taefi 35f6ab8
Merge branch 'main' into taefi/fix-increment-and-remove-add-from-numb…
taefi a5a2738
Merge branch 'main' into taefi/fix-increment-and-remove-add-from-numb…
platosha 4bd7694
Merge branch 'main' into taefi/fix-increment-and-remove-add-from-numb…
platosha File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -134,7 +134,7 @@ public void constructor_withJsonInvalidEventType_shouldThrowInvalidEventTypeExce | |
StateEvent.InvalidEventTypeException.class, | ||
() -> new StateEvent<>(json, String.class)); | ||
|
||
String expectedMessage = "Invalid event type invalidType. Type should be either of: [SNAPSHOT, SET, REPLACE, REJECT]"; | ||
String expectedMessage = "Invalid event type invalidType. Type should be either of: [SNAPSHOT, SET, REPLACE, REJECT, INCREMENT]"; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. "either of" is rather used with two options. Should be "one of". |
||
String actualMessage = exception.getMessage(); | ||
|
||
assertTrue(actualMessage.contains(expectedMessage)); | ||
|
@@ -153,7 +153,7 @@ public void constructor_withJsonMissingEventType_shouldThrowInvalidEventTypeExce | |
StateEvent.InvalidEventTypeException.class, | ||
() -> new StateEvent<>(json, String.class)); | ||
|
||
String expectedMessage = "Missing event type. Type is required, and should be either of: [SNAPSHOT, SET, REPLACE, REJECT]"; | ||
String expectedMessage = "Missing event type. Type is required, and should be either of: [SNAPSHOT, SET, REPLACE, REJECT, INCREMENT]"; | ||
String actualMessage = exception.getMessage(); | ||
|
||
assertTrue(actualMessage.contains(expectedMessage)); | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
import { createIncrementStateEvent } from './events.js'; | ||
import { $update } from './FullStackSignal.js'; | ||
import { ValueSignal } from './ValueSignal.js'; | ||
|
||
/** | ||
* A signal that holds a number value. The underlying | ||
* value of this signal is stored and updated as a | ||
* shared value on the server. | ||
* | ||
* After obtaining the NumberSignal instance from | ||
* a server-side service that returns one, the value | ||
* can be updated using the `value` property, | ||
* and it can be read with or without the | ||
* `value` property (similar to a normal signal): | ||
* | ||
* @example | ||
* ```tsx | ||
* const counter = CounterService.counter(); | ||
* | ||
* return ( | ||
* <Button onClick={() => counter.incrementBy(1)}> | ||
* Click count: { counter } | ||
* </Button> | ||
* <Button onClick={() => counter.value = 0}>Reset</Button> | ||
* ); | ||
* ``` | ||
*/ | ||
export class NumberSignal extends ValueSignal<number> { | ||
/** | ||
* Increments the value by the specified delta. The delta can be negative to | ||
* decrease the value. | ||
* | ||
* This method differs from using the `++` or `+=` operators directly on the | ||
* signal value. It performs an atomic operation to prevent conflicts from | ||
* concurrent changes, ensuring that other users' modifications are not | ||
* accidentally overwritten. | ||
* | ||
* @param delta - The delta to increment the value by. The delta can be | ||
* negative. | ||
*/ | ||
incrementBy(delta: number): void { | ||
if (delta === 0) { | ||
return; | ||
} | ||
this.setValueLocal(this.value + delta); | ||
const event = createIncrementStateEvent(delta); | ||
this[$update](event); | ||
} | ||
} |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
valueOf
is slightly better thanparseDouble
here (IDE suggestion)