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

Strong mode mirror support for rpc package #138

Merged
merged 8 commits into from
Jan 22, 2019

Conversation

jcollins-g
Copy link
Contributor

Fixes #133.

@supermuka

I believe this should be a complete set of changes for the rpc package to support strong-mode mirrors (dart-lang/sdk#35611). It passes all tests on Dart 2.0.0, Dart 2.1.0, and bleeding edge (with strong-mode mirrors) and seems to work just fine with dart-services.

@jcollins-g
Copy link
Contributor Author

If we were planning to maintain this package long term I'd probably follow this up with a refactoring of how rpc reports type problems back to clients.

@jcollins-g jcollins-g requested a review from kevmoo January 17, 2019 23:31
@kevmoo
Copy link
Contributor

kevmoo commented Jan 17, 2019

@jcollins-g – you've double checked the tests? I'm freshly nervous about no CI.

@jcollins-g
Copy link
Contributor Author

@kevmoo Yes, and I will check a third time before submitting. :-)

@supermuka
Copy link

@jcollins-g, I tested and it works fine now in my use case.

.toString() ==
'List<MediaMessage>' &&
request[prop.name] is MediaMessage) {
schema.setField(sym, [request[prop.name]]);
Copy link

Choose a reason for hiding this comment

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

Note that here [request[prop.name]] is List<dynamic> but you want List<MediaMessage>.

Consider doing

final val = request[prop.name]; after if (request.containsKey(prop.name)).

in this case val is MediaMessage should promote val and [val] should get correct reified type.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

done, with more descriptive variable name

// If in form, there is an (input[type="file"] multiple) and the user
// put only one file. It's not an error and it should be accept.
// Maybe it cans be optimized.
if (schema.type.instanceMembers[sym].returnType.reflectedType
Copy link

Choose a reason for hiding this comment

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

I would make a global:

final Type listOfMediaMessage = reflectType(List, [MediaMessage]).reflectedType;

Then here you could just do .returnType.reflectedType == listOfMediaMessages which looks better then comparing strings.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I think we can do better, still. .returnType.reflectedType is List<MediaMessage> works and is sufficiently close to the original comparison for our needs.

Copy link

Choose a reason for hiding this comment

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

.returnType.reflectedType is List<MediaMessage> is always false because reflectedType returns Type and Type is never an instance of List<MediaMessage>.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Ugh, right. Done.

Copy link
Contributor Author

@jcollins-g jcollins-g left a comment

Choose a reason for hiding this comment

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

Updated wrt comments and retested; will land and publish shortly after a full end-to-end test with dart-services.

// If in form, there is an (input[type="file"] multiple) and the user
// put only one file. It's not an error and it should be accept.
// Maybe it cans be optimized.
if (schema.type.instanceMembers[sym].returnType.reflectedType
Copy link
Contributor Author

Choose a reason for hiding this comment

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

I think we can do better, still. .returnType.reflectedType is List<MediaMessage> works and is sufficiently close to the original comparison for our needs.

.toString() ==
'List<MediaMessage>' &&
request[prop.name] is MediaMessage) {
schema.setField(sym, [request[prop.name]]);
Copy link
Contributor Author

Choose a reason for hiding this comment

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

done, with more descriptive variable name

@jcollins-g
Copy link
Contributor Author

Retested with 2.0.0, 2.1.0, and 2.1.1-dev-1.0. Landing and will publish shortly.

@jcollins-g jcollins-g merged commit 673cf79 into master Jan 22, 2019
@jcollins-g jcollins-g deleted the experimental-mirrors-refactor branch January 22, 2019 18:08
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

Successfully merging this pull request may close these issues.

5 participants