-
Notifications
You must be signed in to change notification settings - Fork 0
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
Conversation
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.:
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.
Fix the type of the newValue
in the verify
function
lib/State.ts
Outdated
* @param {T} newValue | ||
* @returns {boolean} | ||
*/ | ||
verifyValue(newValue: string) { |
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.
The newValue
should be of generic type T
* @returns {boolean} | ||
*/ | ||
verifyValue(newValue: T): boolean { | ||
return this.value !== newValue; |
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.
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.
This PR optimised the performance of updating a state by only updating if the new value is not equal to the old one.