-
Notifications
You must be signed in to change notification settings - Fork 44
Add typings for JSRecord and some unsafe extensions for JSObject #487
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
base: main
Are you sure you want to change the base?
Conversation
This doesn't include JSObject extensions that require types that aren't defined yet, like JSSymbolicRecord.
|
We should do better on those JS failures in Wasm: dart-lang/sdk#62218 |
| /// The operation is equivalent to doing `this[key] = value` for each key and | ||
| /// associated value in [other]. It iterates over [other], which must therefore | ||
| /// not change during the iteration. | ||
| void addAllRecord(JSRecord<V> other) => addPairs(other.pairs); |
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.
tiny nit: maybe addAllFromRecord instead?
| @JS('Object.values') | ||
| external JSArray<JSAny?> _values(JSObject object); | ||
|
|
||
| /// Additional instance methods for the `dart:js_interop` [interop.JSObject] |
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: remove interop.
| /// See [`Object.entries()`]. | ||
| /// | ||
| /// [`Object.entries()`]: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object/entries | ||
| List<(String, JSAny?)> get entries => [ |
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.
Thoughts on making this a generic method instead so that the second tuple member can be a generic (and therefore avoid the need for a cast list)?
| /// The [name] must be a [JSString] or a [JSSymbol]. | ||
| /// | ||
| /// [`Reflect.get()`]: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Reflect/get | ||
| R getPropertyWithThis<R extends JSAny?>(JSAny name, JSAny? thisArg) => |
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.
I feel like this and setPropertyWithThis are sufficiently different in name that we may want a Reflect type instead, especially if we're planning to add more Reflect members. Thoughts?
js_interop/test/record_test.dart
Outdated
| ); | ||
| }); | ||
|
|
||
| test("addPairs()", () { |
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: did you mean to name this as clear()?
| expect(record.containsKey("foo"), isTrue); | ||
| expect(record.containsKey("baz"), isFalse); | ||
| }); | ||
|
|
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: test for containsValue
| () => | ||
| expect(object.getPropertyWithThis("foo".toJS, object), equals(1.toJS)), | ||
| ); | ||
|
|
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: test for getOwnProperty
|
/gemini review |
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.
Code Review
This pull request introduces JSRecord as a map-like wrapper for JS objects and adds several unsafe extensions for JSObject. The implementation is generally good, but I've found a few areas for improvement, mainly related to performance in JSRecord and some minor issues in documentation and tests. My review includes suggestions to optimize method implementations and fix typos.
This doesn't include JSObject extensions that require types that
aren't defined yet, like JSSymbolicRecord.