-
Notifications
You must be signed in to change notification settings - Fork 1
feat!: remove undefined-to-null conversion warnings and simplify internal APIs #38
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
This stack of pull requests is managed by Graphite. Learn more about stacking. |
1911ba8 to
fc0b806
Compare
rexxars
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.
Not a hill I am willing to die on so will approve, but I don't agree that this was a necessary change 🤷♂️
The fact that JSON.stringify automatically converts undefined to null in arrays but not in objects has always seemed odd to me, and I'd rather have a warning about it than debugging why I am seeing nulls in my arrays.
fc0b806 to
e538df3
Compare
3aff5f8 to
2459585
Compare
Merge activity
|
…rnal APIs BREAKING CHANGE: Remove `hideWarnings` option and associated warning system. The diffPatch function no longer accepts or uses the hideWarnings option. Remove console warnings when undefined values in arrays are converted to null. This conversion behavior aligns with JSON.stringify() which also converts undefined to null, making it relatively expected behavior that doesn't warrant user warnings. The console.log side effects made the library incompatible with some JavaScript environments (like edge workers or serverless functions with restricted console access) and the warning provided minimal value since the conversion behavior matches standard JSON serialization. Internal API changes: - Remove options parameter threading through diffItem, diffObject, diffArray, etc. - Simplify nullifyUndefined() to only handle the conversion without warnings - Remove DEFAULT_OPTIONS constant
e538df3 to
45ef4d1
Compare

This PR introduces two related changes to simplify the library's API and internal logic:
undefinedtonullConversion:The library previously logged a console warning when an
undefinedvalue within an array was converted tonullduring the diffing process. This warning has been removed. The conversion itself remains (asundefinedis not valid JSON andnullis the standard representation for "no value"), but it will no longer produce console output.optionsPropagation:The
hideWarningsoption was the primary reason for propagating theoptionsobject deep into various internal diffing functions (diffItem,diffObject,diffArray,diffArrayByIndex,diffArrayByKey). With the removal of the warning and thehideWarningsoption, this propagation is no longer necessary. These internal functions now have simpler signatures, no longer accepting or passing down theoptionsobject for this purpose.Key Changes:
nullifyUndefinedFunction:path,index, andoptionsparameters.console.warnlog.undefinedtonull, aligning its behavior more closely withJSON.stringify()without side effects.hideWarningsOption:hideWarningsproperty from thePatchOptionsinterface.DEFAULT_OPTIONSconstant as it's no longer needed.optionsparameter has been removed fromdiffItem,diffObject,diffArray,diffArrayByIndex, anddiffArrayByKeyas it was primarily used forhideWarnings. These functions now rely on the default behavior forundefinedhandling.hideWarnings: truefrom test calls todiffPatch.Rationale:
undefinedtonullconversion warning reduces noise in the console, especially for users who frequently work with data that might containundefinedvalues. The conversion tonullis a standard and expected behavior when serializing to JSON-like structures.hideWarningsoption makes the public API slightly leaner.optionsobject through multiple internal functions for the sole purpose ofhideWarningsleads to cleaner and more maintainable internal code.JSON.stringify: The behavior of convertingundefinedin arrays tonullis consistent withJSON.stringify, making the library's behavior more predictable for developers familiar with JSON standards.This change streamlines the library's behavior regarding
undefinedvalues and simplifies its internal option handling.