Skip to content

[2.0.0-dev - dart2] AF-233 Consume react-dart callable class fixes#155

Merged
aaronlademann-wf merged 21 commits into2.0.0-devfrom
dart2
May 18, 2018
Merged

[2.0.0-dev - dart2] AF-233 Consume react-dart callable class fixes#155
aaronlademann-wf merged 21 commits into2.0.0-devfrom
dart2

Conversation

@aaronlademann-wf
Copy link
Contributor

Depends on Workiva/react-dart#142

Problem(s):

  1. In the Dart 2 SDK, the assignment of an object with a call method to a function type will now be treated as an implicit closurization of the .call method of the object. This is not compatible with how ReactComponentFactory works.
  2. The MapBase additions from #151are no longer the best way to satisfy the missing concrete Map class impls.
  3. Misc. housekeeping items need to be addressed to get the 2.0.0-dev branch ready to support further Dart 2 SDK testing / 2.0.0-dev.<n> releases as the Dart team moves closer and closer to a production release of the Dart 2 SDK.

Solution(s):

  1. Consume the [5.0.0-dev - dart2] AF-222 Fix Dart 2 Callable Classes Issues react-dart#142 callable class fixes
  2. The MapBase additions from AF-223 Begin preparations for Dart SDK 2 #151 were reverted and the new fields / getters / methods from that are present on the Map class in the Dart 2 SDK were instead implemented individually so we don't add a bunch of stuff from dart:collection that we don't actually need.
  3. Address housekeeping items
    1. Update Dart SDK dependency range to >=2.0.0-dev.0 <=2.0.0-dev.49.0
    2. Address any lints / hints / errors found when the analysis server in Dart w.0.0-dev.49.0 runs

Testing Instructions:

  1. Switch your Dart SDK to 2.0.0-dev.49.0
  2. Serve the examples using the DDC:
    pub serve --web-compiler=dartdevc
  3. Load http://localhost:8080 and play around with the example components.
  4. Verify that the examples work as expected without producing run time errors

Known Issues:

There are some issues present that, upon some investigation, appear to be unrelated to these changes:

  1. There are numerous test failures centered around type casting. I am unsure if this is a test package issue, or if we need to do away with some of our "shared" test suites.

FYA: @greglittlefield-wf @clairesarsam-wf

FYI: @dustinlessard-wf @sebastianmalysa-wf @robbecker-wf

@aviary3-wk
Copy link

Security Insights

No security relevant content was detected by automated scans.

Action Items

  • Review PR for security impact; comment "security review required" if needed or unsure
  • Verify aviary.yaml coverage of security relevant code

Questions or Comments? Reach out on HipChat: InfoSec Forum.

@aaronlademann-wf
Copy link
Contributor Author

@greglittlefield-wf I don't think we'll be able to get a passing travis build until https://github.com/cleandart/react-dart/pull/142/files is merged / released as 5.0.0-dev.alpha.0. Travis doesn't seem to like git dependencies

@aaronlademann-wf
Copy link
Contributor Author

Also, once https://github.com/Workiva/smithy-runner-dart/pull/48 goes through we should be able to get the smithy build passing as well.

Copy link
Contributor

@greglittlefield-wf greglittlefield-wf left a comment

Choose a reason for hiding this comment

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

Looks good, mostly some comments about the map class stuff

@mustCallSuper
@override
void redraw([callback()]) {
void redraw([Function callback]) {
Copy link
Contributor

Choose a reason for hiding this comment

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

This should be changed back (is this leftover from when it was typed to Function previously in react-dart?)

/// > Necessary for eventual upgrade to the Dart 2 SDK.
abstract class _OverReactMapBase<K, V> extends Object implements MapViewMixin<K, V>, Map<K, V> {
// Manually implement members from `Map` that appear in the Dart 2 SDK
// without having to extend from `MapBase`.
Copy link
Contributor

Choose a reason for hiding this comment

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

#nit I think this comment implies the wrong thing; we don't want to extend from MapBase because we want to just proxy that map.

Perhaps this class should be called _MapProxy or _OverReactMapView


// Manually implement members from `MapViewMixin`,
// since mixing that class in doesn't play well with the DDC.
// TODO find out root cause and reduced test case.
Copy link
Contributor

Choose a reason for hiding this comment

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

I think this block of comments is now outdated and can be removed, right?

/// > Note: Implements [MapViewMixin] instead of extending it so that the abstract [Props] declarations
/// don't need a constructor. The generated implementations can mix that functionality in.
abstract class UiProps extends MapBase
abstract class UiProps<K, V> extends _OverReactMapBase<K, V>
Copy link
Contributor

Choose a reason for hiding this comment

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

Is there a reason generic parameters were added to UiProps/UiState (and other places)? I'm concerned that that might introduce type complexity in props class inheritances (which can be problematic in dart2js; see dart-lang/sdk#14729) without providing much benefit.

@override remove(Object key) => _map.remove(key);
@override Iterable get values => _map.values;

// Manually implement members from `StateMapViewMixin`,
Copy link
Contributor

Choose a reason for hiding this comment

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

(I think StateMapViewMixin is a typo and should say PropsMapViewMixin.)

Could we try mixing in `PropsMapViewMixin instead and see how it works with Dart 2's DDC?

});
// TODO: The typing for `customFactory` is an analyzer error in Dart 2 (dev.49), is this DDC workaround + test still necessary or can it be removed?
//
// NOTE: This is no longer supportable in Dart 2 (should advertise as a breaking change in release notes)
Copy link
Contributor

Choose a reason for hiding this comment

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

Actually, can we just remove this test? We don't intend on doing anything with it, and we know this is going to break.


@override
void setState(_, [callback()]) {
void setState(_, [Function callback]) {
Copy link
Contributor

Choose a reason for hiding this comment

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

This and its friends should be reverted as well.

when(mock.addAll(any)).thenReturn('value');

expect(proxy.addAll(testMap), isNull);
expect(() => proxy.addAll(testMap), isNull);
Copy link
Contributor

Choose a reason for hiding this comment

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

Huh, you can pass in a function and expect will evaluate it and match the result? Is this documented somewhere?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

That I don't know for sure @greglittlefield-wf ... I did this to address a dart 2 analyzer error, and the test didn't fail. I didn't dig too much further into it.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

In addition, these test are currently not run in the DDC because they us mirrors.

Copy link
Contributor

Choose a reason for hiding this comment

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

It looks like it doesn't work. This is causing failures in Dart 1:

00:16 +245 -20: [Chrome] test/over_react_component_declaration_test.dart: component base: UiState provides Map functionality: proxies the Map member: forEach [E]
  Expected: null
    Actual: <Closure: () => void from: () => proxy[$forEach](callback)>
  
  package:test                                 expect
  over_react/shared/map_proxy_tests.dart 86:7  test.test.dart.fn

We'll have to find a different workaround for this issue; perhaps we just shouldn't assert the return value. Or just comment out the tests until we're running them in Dart 2.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@greglittlefield-wf this branch is targeting an SDK version of 2.0.0-dev.49.0, I wouldn't expect a lot of tests in this branch to pass using the dart 1 SDK.

expect(() => proxy.forEach(callback), isNull);
verify(mock.forEach(callback));
});

Copy link
Contributor

Choose a reason for hiding this comment

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

We should add tests for the new Dart 2 Map members as well

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@greglittlefield-wf agreed, but currently, these tests are skipped in the DDC because they make use of mirrors.

Copy link
Contributor

Choose a reason for hiding this comment

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

Yeah, at some point, we need to update these tests to use DDC-compatible mocks, or to not use mocks at all.

We do need some kind of test coverage around these methods; we should at least stub out these tests with FIXMEs or something so that we add them by the time we release these changes as stable.

import 'package:over_react/over_react.dart';
import 'package:test/test.dart';

typedef dynamic ChainFunction([_, __, ___, ____, _____, ______]);
Copy link
Contributor

Choose a reason for hiding this comment

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

I think this ended up being unused.

@aaronlademann-wf aaronlademann-wf force-pushed the dart2 branch 2 times, most recently from 2eac0f7 to 492c653 Compare May 10, 2018 23:52
Copy link
Contributor

@greglittlefield-wf greglittlefield-wf left a comment

Choose a reason for hiding this comment

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

A couple things, but should be ready after this pass!

when(mock.addAll(any)).thenReturn('value');

expect(proxy.addAll(testMap), isNull);
expect(() => proxy.addAll(testMap), isNull);
Copy link
Contributor

Choose a reason for hiding this comment

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

It looks like it doesn't work. This is causing failures in Dart 1:

00:16 +245 -20: [Chrome] test/over_react_component_declaration_test.dart: component base: UiState provides Map functionality: proxies the Map member: forEach [E]
  Expected: null
    Actual: <Closure: () => void from: () => proxy[$forEach](callback)>
  
  package:test                                 expect
  over_react/shared/map_proxy_tests.dart 86:7  test.test.dart.fn

We'll have to find a different workaround for this issue; perhaps we just shouldn't assert the return value. Or just comment out the tests until we're running them in Dart 2.

expect(() => proxy.forEach(callback), isNull);
verify(mock.forEach(callback));
});

Copy link
Contributor

Choose a reason for hiding this comment

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

Yeah, at some point, we need to update these tests to use DDC-compatible mocks, or to not use mocks at all.

We do need some kind of test coverage around these methods; we should at least stub out these tests with FIXMEs or something so that we add them by the time we release these changes as stable.

}
}

// Manually implement members from `MapViewMixin`,
Copy link
Contributor

Choose a reason for hiding this comment

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

This branch looks so much better than what we currently have!

There are a few more things that could be cleaned up, though, and since they're hard to explain I've just made a PR into this branch: #158.

Clean up the rest of the Map grossness left over from DDC workarounds
@aaronlademann-wf
Copy link
Contributor Author

@greglittlefield-wf I've merged in your changes, and your comments about the () => proxy thing not working in Dart 1 - I'm not sure they're really relevant since this is merging into the 2.0.0 branch which is a dart 2 SDK "working" branch.

I have tests passing locally - although there is likely still some work to be done getting them passing in Travis. I think this is a good first step though, and I'd like to get this merged unless there are major objections by you or @clairesarsam-wf.

@greglittlefield-wf
Copy link
Contributor

@aaronlademann-wf I'd rather us just comment out the tests than check in invalid changes just to fix syntax errors.

We do need some kind of test coverage around these methods; we should at least stub out these tests with FIXMEs or something so that we add them by the time we release these changes as stable.

I also think we should stub those in so we don't forget about it.

@clairesarsam-wf
Copy link
Contributor

+10

  • Examples page renders as expected with no runtime errors

@aaronlademann-wf aaronlademann-wf merged commit c7d3d70 into 2.0.0-dev May 18, 2018
@aaronlademann-wf aaronlademann-wf added the dart2 PRs targeting our effort to get to Dart SDK 2.0 compatibility label Sep 7, 2018
@aaronlademann-wf aaronlademann-wf added this to the 2.0.0 milestone Sep 7, 2018
@aaronlademann-wf aaronlademann-wf deleted the dart2 branch September 7, 2018 23:26
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.

6 participants