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

JS-object-based props/state, Component2 initial impl, JsMap #161

Merged

Conversation

greglittlefield-wf
Copy link
Collaborator

@greglittlefield-wf greglittlefield-wf commented Mar 4, 2019

Changes

Initial implementation of JS-object-based props/state

  • Implemented in new Component2 base class
    • This API is extremely far from final; it currently contains pieces that will be removed or completely reworked before release
  • Dart component props are now stored directly on the JS props object, as opposed to within a Dart object stored as an internal prop
  • Dart component state is now also stored directly on the JS state object, as opposed to completely within the Dart layer

Advantages:

  • Props/state are now visible/mutable in the React Dev Tools, greatly improving the Dart component debugging experience
  • Complexity of the Dart/JS bindings are reduced significantly by leveraging React JS logic more directly, allowing easier maintenance and reduced risk of bugs
    • This will be especially important when implementing the new React lifecycle methods and concurrent mode
  • Performance is increased by a small amount by avoiding Dart Map overhead

JsBackedMap

A Dart class that adapts JS objects to the Dart Map interface, allowing properties to be easily read/written directly.

  • Used as the basis for props/state Maps used in Component2's fields and lifecycle methods
  • Used to replace some existing logic in ReactDomComponentFactory that served similar functions, removing an extra copy in DOM ReactElement creation

Etc.

  • Update tests to run on Component2
  • Add basic tests for JsBackedMap (more test coverage will come in a later PR)
  • Bump SDK constraint to be Dart-2-only
  • Remove Dart 1 build from CI

Testing

  • CI passes

# Conflicts:
#	example/test/react_test_components.dart
#	lib/react.dart
#	lib/react_client.dart
#	lib/react_client/react_interop.dart
#	test/factory/common_factory_tests.dart
#	test/lifecycle_test.dart
…rt_1

Also add polyfills to build

# Conflicts:
#	example/test/react_test_components.dart
#	js_src/dart_helpers.js
#	lib/react.js
#	lib/react_client/react_interop.dart
#	lib/react_prod.js
#	lib/react_with_addons.js
#	lib/react_with_react_dom_prod.js
#	test/ReactSetStateTestComponent.js
#	test/lifecycle_test.dart
@greglittlefield-wf greglittlefield-wf changed the title JS-object-based props, Component2 initial impl, JsMap JS-object-based props/state, Component2 initial impl, JsMap Mar 4, 2019
Copy link
Collaborator

@aaronlademann-wf aaronlademann-wf left a comment

Choose a reason for hiding this comment

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

Additional feedback here: greglittlefield-wf#2

@@ -7,7 +7,8 @@ library react;

import 'package:react/src/typedefs.dart';

typedef Component ComponentFactory();
// todo revert this?
typedef T ComponentFactory<T extends Component>();
Copy link
Collaborator

Choose a reason for hiding this comment

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

I don't see any reason to revert it... its not a breaking API change as far as I can tell....

lib/react_client/react_interop.dart Outdated Show resolved Hide resolved
@Workiva Workiva deleted a comment from thegregorator Mar 6, 2019
Copy link
Collaborator

@kealjones-wk kealjones-wk left a comment

Choose a reason for hiding this comment

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

Looks super good! so excited, just some nits and questions.

lib/react.dart Outdated Show resolved Hide resolved
lib/react_client.dart Outdated Show resolved Hide resolved
lib/react.dart Outdated Show resolved Hide resolved
lib/react_client.dart Outdated Show resolved Hide resolved
lib/react_client.dart Outdated Show resolved Hide resolved
@override
bool containsKey(Object key) {
// if (!_isValidKey(key)) return false;
// assert(_isValidKey(key));
Copy link
Collaborator

Choose a reason for hiding this comment

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

and again, more guff


// overridden for to avoid cast in case the implementation of keys changes
// @override
// int get length => _Object.keys(jsObject).length;
Copy link
Collaborator

Choose a reason for hiding this comment

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

from line 99 to here all can probably go, unless the worry of implementation change is still relevant then id probably un-comment it out.

lib/react.dart Outdated Show resolved Hide resolved
///
/// Will be removed when [Component] is removed in the `6.0.0` release.
@Deprecated('6.0.0')
void replaceState(Map newState, [SetStateCallback callback]) =>
Copy link
Collaborator

Choose a reason for hiding this comment

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

Why is this deprecated in Component2 and not in Component? why do we even need this in Component2?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Good point, it should probably be deprecated in Component, along with any other non-lifecycle members that will be unsupported in Component2.

Copy link
Collaborator

Choose a reason for hiding this comment

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

I will add "non lifecycle members of Component" to our deprecation ticket.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

I say we do that in the PR where we add all the other deprecations

lib/react_client.dart Outdated Show resolved Hide resolved
Copy link
Collaborator

@kealjones-wk kealjones-wk left a comment

Choose a reason for hiding this comment

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

+10

Copy link
Collaborator

@aaronlademann-wf aaronlademann-wf left a comment

Choose a reason for hiding this comment

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

+1

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants