Skip to content

CPLAT-4107 Remove getJsProps() #233

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

Merged
merged 3 commits into from
Feb 8, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
31 changes: 2 additions & 29 deletions lib/src/util/react_wrappers.dart
Original file line number Diff line number Diff line change
Expand Up @@ -71,33 +71,6 @@ bool isDartComponent(/* ReactElement|ReactComponent|Element */ instance) {
return _getInternal(instance) != null;
}

@JS('Object.keys')
external Iterable _objectKeys(object);

/// Returns a Dart Map copy of the JS property key-value pairs in [jsMap].
Map _dartifyJsMap(jsMap) {
return new Map.fromIterable(_objectKeys(jsMap),
value: (key) => getProperty(jsMap, key)
);
}

/// Returns the props for a [ReactElement] or composite [ReactComponent] [instance],
/// shallow-converted to a Dart Map for convenience.
///
/// If `style` is specified in props, then it too is shallow-converted and included
/// in the returned Map.
Map getJsProps(/* ReactElement|ReactComponent */ instance) {
var props = _dartifyJsMap(instance.props);

// Convert the nested style map so it can be read by Dart code.
var style = props['style'];
if (style != null) {
props['style'] = _dartifyJsMap(style);
}

return props;
}

/// Whether [Expando]s can be used on [ReactElement]s.
///
/// At the time this was written, this should return:
Expand Down Expand Up @@ -128,7 +101,7 @@ final Expando<UnmodifiableMapView> _elementPropsCache = _canUseExpandoOnReactEle
/// Returns an unmodifiable Map view of props for a [ReactElement] or composite [ReactComponent] [instance].
///
/// For a native Dart component, this returns its [react.Component.props] in an unmodifiable Map view.
/// For a JS component, this returns the result of [getJsProps] in an unmodifiable Map view.
/// For a JS component, this returns the result of [unconvertJsProps] in an unmodifiable Map view.
///
/// If [traverseWrappers] is `true` then it will return an unmodifiable Map view of props of the first non-"Wrapper"
/// instance.
Expand Down Expand Up @@ -167,7 +140,7 @@ Map getProps(/* ReactElement|ReactComponent */ instance, {bool traverseWrappers:
if (cachedView != null) return cachedView;
}

var propsMap = isDartComponent(instance) ? _getExtendedProps(instance) : getJsProps(instance);
var propsMap = isDartComponent(instance) ? _getExtendedProps(instance) : unconvertJsProps(instance);
var view = new UnmodifiableMapView(propsMap);

if (_elementPropsCache != null && !isCompositeComponent) {
Expand Down
3 changes: 1 addition & 2 deletions pubspec.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ dependencies:
logging: ">=0.11.3+2 <1.0.0"
meta: ^1.1.6
path: ^1.5.1
react: ^4.5.0
react: ^4.6.0
source_gen: ^0.9.0
source_span: ^1.4.1
transformer_utils: ^0.2.0
Expand All @@ -39,4 +39,3 @@ dev_dependencies:
mockito: ^4.0.0
over_react_test: ^2.2.0
test: ^1.0.0

Original file line number Diff line number Diff line change
Expand Up @@ -940,7 +940,7 @@ main() {
});
}

dynamic getJsChildren(instance) => getJsProps(instance)['children'];
dynamic getJsChildren(instance) => unconvertJsProps(instance)['children'];

dynamic getDartChildren(var renderedInstance) {
assert(isDartComponent(renderedInstance));
Expand Down
16 changes: 8 additions & 8 deletions test/over_react/util/react_wrappers_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -50,8 +50,8 @@ main() {
// If these objects are equal, then they proxy the same JS props object.
expect(clone.props, isNot(equals(original.props)));

Map originalProps = getJsProps(original);
Map cloneProps = getJsProps(clone);
Map originalProps = unconvertJsProps(original);
Map cloneProps = unconvertJsProps(clone);

// Verify all props (children included) are equal.
expect(cloneProps, equals(originalProps));
Expand All @@ -64,8 +64,8 @@ main() {
// If these objects are equal, then they proxy the same JS props object.
expect(clone.props, isNot(equals(original.props)));

Map originalProps = getJsProps(original);
Map cloneProps = getJsProps(clone);
Map originalProps = unconvertJsProps(original);
Map cloneProps = unconvertJsProps(clone);

// Verify all props (including children, excluding react-dart internals) are equal.
Map originalShallowProps = new Map.from(originalProps);
Expand Down Expand Up @@ -105,7 +105,7 @@ main() {
var original = (Dom.div()..addProps(testProps))(testChildren);
var clone = cloneElement(original, testPropsToAdd);

Map cloneProps = getJsProps(clone);
Map cloneProps = unconvertJsProps(clone);

// Verify all props (children included) are equal.
expect(cloneProps, equals(expectedPropsMerge));
Expand Down Expand Up @@ -196,7 +196,7 @@ main() {
var clone = cloneElement(original, testPropsToAdd);

var renderedClone = react_test_utils.renderIntoDocument(clone);
Map cloneProps = getJsProps(renderedClone);
Map cloneProps = unconvertJsProps(renderedClone);

expect(() {
// Retrieve an automatically JS-proxied version of the callback passed to the component.
Expand Down Expand Up @@ -281,7 +281,7 @@ main() {
var original = (Dom.div()..addProps(testProps))(testChildren);
var clone = cloneElement(original, null, testOverrideChildren);

Map cloneProps = getJsProps(clone);
Map cloneProps = unconvertJsProps(clone);

expect(cloneProps['children'], equals(testOverrideChildren));
});
Expand All @@ -293,7 +293,7 @@ main() {
var renderedClone = render(clone);

// Verify that children are overridden according to React
Map cloneProps = getJsProps(renderedClone);
Map cloneProps = unconvertJsProps(renderedClone);
expect(cloneProps['children'], equals(testOverrideChildren));

// Verify that children are overridden according to the Dart component.
Expand Down