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

fix(iOS): preserve null values in bridged types #4072

Merged
merged 5 commits into from
Jan 21, 2021
Merged

fix(iOS): preserve null values in bridged types #4072

merged 5 commits into from
Jan 21, 2021

Conversation

ikeith
Copy link
Contributor

@ikeith ikeith commented Jan 15, 2021

This branch extends JSValue to include NSNull in order to preserve null values sent from JS. It also adds some small extensions to Array to improve the ergonomics when working in Swift, and adds unit tests to document and verify the behavior.

This branch also deprecates hasOption on CAPPluginCall as the presence of a key in the options isn't significant and we shouldn't encourage that pattern. Typing the represented value if it is not nil is more meaningful.

This addresses the underlying cause that #4048 worked around.

@ikeith ikeith added this to the 3.0.0 milestone Jan 15, 2021
Copy link
Contributor

@imhoffd imhoffd left a comment

Choose a reason for hiding this comment

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

Would adding a test for [JSValue?] and heterogeneous arrays make sense (in BridgedTypesTests.swift)?

@ikeith
Copy link
Contributor Author

ikeith commented Jan 18, 2021

Would adding a test for [JSValue?] and heterogeneous arrays make sense (in BridgedTypesTests.swift)?

More tests are good, but I'm not clear on what use-case you're suggesting covering?

@imhoffd imhoffd modified the milestones: 3.0.0, 3.0.0-rc Jan 19, 2021
@imhoffd
Copy link
Contributor

imhoffd commented Jan 19, 2021

@ikeith Does something like this make sense?

let array: [Any] = ["test string 1", 1, NSNull()]
let sparseArray = JSTypes.coerceArrayToJSArray(array)?.capacitor.replacingNullValues() as? [JSValue?]
// sparseArray should cast successfully and not be nil

@ikeith
Copy link
Contributor Author

ikeith commented Jan 21, 2021

@dwieeb That kind of test was already added to the test suite: testSparseArrayCastSuccess in BridgedTypesTests.swift

@imhoffd imhoffd merged commit 6dc691e into main Jan 21, 2021
@imhoffd imhoffd deleted the null-support branch January 21, 2021 18:30
@imhoffd imhoffd modified the milestones: 3.0.0-rc, 3.0.0-beta.2 Jan 29, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants