-
Notifications
You must be signed in to change notification settings - Fork 5.7k
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
[core][ios] Use key paths to refer to shared object properties #20610
Conversation
"object.immutableKeyPathProperty" | ||
]) | ||
|
||
// Returned value didn't change, it doesn't equal to `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.
nit: would be even better if updating immutable property could have a compiler-time or build-time error. not sure whether it's feasible or not.
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.
No, it doesn't seem possible, it's just a JS 🤷♂️ We can throw an error at runtime, but the current implementation is the same as in JS. Even Object.defineProperty(obj, "key", { writable: false })
still lets you do the assignment operation, but it's just a no-op and will return undefined
when you read that property.
Also, I think it would be nice to add some attributes to the Property
, such as writable
, enumerable
and readonly
. The last one is not a part of the descriptor but it could change the behavior so that we throw an error when you try setting that property.
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 Object.defineProperty(obj, "key", { writable: false })
with no-op setter makes sense to me. thanks!
Hi there! 👋 I'm a bot whose goal is to ensure your contributions meet our guidelines. I've found some issues in your pull request that should be addressed (click on them for more details) 👇
|
@@ -12,6 +12,7 @@ | |||
- Trailing optional arguments can be skipped when calling native functions from JavaScript on iOS. ([#20234](https://github.com/expo/expo/pull/20234) by [@tsapeta](https://github.com/tsapeta)) | |||
- `Events` component can now be initialized with an array of event names (not only variadic arguments). ([#20590](https://github.com/expo/expo/pull/20590) by [@tsapeta](https://github.com/tsapeta)) | |||
- `Property` component can now take the native shared object instance as the first argument. ([#20608](https://github.com/expo/expo/pull/20608) by [@tsapeta](https://github.com/tsapeta)) | |||
- Added support for referencing to `Property`'s owner properties using Swift key paths. |
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.
- Added support for referencing to `Property`'s owner properties using Swift key paths. | |
- Added support for referencing to `Property`'s owner properties using Swift key paths. ([#20610](https://github.com/expo/expo/pull/20610) by [@tsapeta](https://github.com/tsapeta)) |
Why
Implementing one of the ideas proposed in #20543
This introduces a syntactic sugar for the following:
which could be replaced with the component that takes the key path
Moreover, if the property is mutable (
var
property), it automatically sets the property setter too 🙂How
Property
definition that support Swift key paths (KeyPath
forlet
properties andReferenceWritableKeyPath
forvar
properties in classes)Test Plan
It's all green in native unit tests