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

🥸 : Optimise updating state #3

Merged
merged 5 commits into from
Jul 30, 2022
Merged

🥸 : Optimise updating state #3

merged 5 commits into from
Jul 30, 2022

Conversation

haneenmahd
Copy link
Owner

This PR optimised the performance of updating a state by only updating if the new value is not equal to the old one.

I have optimised the performance by adding a verify function to verify if
there are changes in the state's value. This is done by comparing the old
value with the new one. This thus helps in less energy, CPU usage in large
apps.:
@haneenmahd haneenmahd added the enhancement New feature or request label Jul 30, 2022
@haneenmahd haneenmahd added this to the v1 🚀 milestone Jul 30, 2022
@haneenmahd haneenmahd self-assigned this Jul 30, 2022
Copy link
Owner Author

@haneenmahd haneenmahd left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fix the type of the newValue in the verify function

lib/State.ts Outdated
* @param {T} newValue
* @returns {boolean}
*/
verifyValue(newValue: string) {
Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The newValue should be of generic type T

* @returns {boolean}
*/
verifyValue(newValue: T): boolean {
return this.value !== newValue;
Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Previously, I compared if it is equal to the new value and resulted in a bug, that will prevent from setting the state value. Now, we will verify if the value is not same as the old one.

@haneenmahd haneenmahd merged commit 0648335 into main Jul 30, 2022
@haneenmahd haneenmahd deleted the optimise-state-setter branch July 30, 2022 02:33
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

1 participant