-
-
Notifications
You must be signed in to change notification settings - Fork 6
Introduce ReturnFormat option to allow detailed or value-only outputs #9
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
Conversation
bramus
left a comment
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.
For the extended return format I’d like to retain the original object structure instead of changing to an array. So it’d be something like this:
{
"--my-variable": {
"propertyName": "--my-variable",
"value": "1.0",
"previousValue": "0.0",
"changed": true
},
"display": {
"propertyName": "display",
"value": "block",
"previousValue": "block",
"changed": false
},
}
That way, it’s easy to switch between return formats. If authors want to easily loop, they can always pass this result into Object.entries/Object.values.
Does that make sense?
|
Absolutely, that makes sense and would simplify switching between return formats - I have made the changes accordingly! I did notice that the {
"--my-variable": {
"value": "1.0",
"previousValue": "0.0",
"changed": true
},
"display": {
"value": "block",
"previousValue": "block",
"changed": false
}
}your thoughts on this? |
|
Yeah, makes sense. Devs should use |
Co-authored-by: Bramus <bramus@bram.us>
Co-authored-by: Bramus <bramus@bram.us>
Co-authored-by: Bramus <bramus@bram.us>
Co-authored-by: Bramus <bramus@bram.us>
Co-authored-by: Bramus <bramus@bram.us>
bramus
left a comment
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.
Thanks for the updates!
There is still some unnecessary dependency chain between the functions here, namely _returnFormatHandlers calling _processObservedVariables, which I think can be avoided.
Ideally these two functions would be decoupled, so that they are standalone:
_processObservedVariablesto only return a list of changes_returnFormatHandlersto only return a formatting function
The _handleUpdate function can then tie them together, by passing the list of changes into the handler, after which it passed those formattedChanges into the _callback.
src/index.ts
Outdated
| const hasChanged = currentValue !== previousValue; | ||
|
|
||
| if (this._notificationMode === NotificationMode.ALL || hasChanged) { | ||
| changes.push(processChange(propertyName, currentValue, previousValue, hasChanged)); |
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.
Can you refactor this so that it does not call processChange here, but that it only stores the change object?
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.
refactored as requested
src/index.ts
Outdated
| /** | ||
| * Handlers for return formats | ||
| */ | ||
| private _returnFormatHandlers: Record<ReturnFormat, (computedStyle: CSSStyleDeclaration) => CSSDeclarations | { [key: string]: CSSPropertyInfo }> = { |
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.
Ideally, these would only return a processing function, not actually call _processObservedVariables
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.
refactored as requested
Co-authored-by: Bramus <bramus@bram.us>
This Pull Request addresses #8 by introducing a new
ReturnFormatoption to the CSSStyleObserver. This enhancement allows users to choose between receiving only the current values of observed CSS properties or detailed information that includes previous values and change statusesChanges
ReturnFormatenum with optionsVALUE_ONLY(default) andOBJECTCSSStyleObserverclass to process observed properties based on the selectedReturnFormatREADME.mdto reflect the newReturnFormatoption and provide usage examples