Skip to content

Commit 0faf5ff

Browse files
Merge pull request #234 from Workiva/remove_deprecated_usages_of_getJsProps
CPLAT-4129: Use `unconvertJsProps()` instead of `getJsProps()`
2 parents ff8d201 + a10c4ec commit 0faf5ff

File tree

5 files changed

+18
-31
lines changed

5 files changed

+18
-31
lines changed

CHANGELOG.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,11 @@ __Deprecations__
1111
* `$Props` and `$PropKeys` - see the [Dart 2 migration guide](https://github.com/Workiva/over_react/blob/master/doc/dart2_migration.md)
1212
for more information.
1313

14+
* [#207] Override `call()` instead of `noSuchMethod()` in the `UiProps` class.
15+
This was a requirement for Dart 2 compatibility, but also serves as an
16+
improvement - by no longer overriding `noSuchMethod()`, we will no longer be
17+
obscuring certain analyzer errors that should be seen by consumers.
18+
1419
## 1.30.2
1520

1621
> [Complete `1.30.2` Changeset](https://github.com/Workiva/over_react/compare/1.30.1...1.30.2)

lib/src/util/react_wrappers.dart

Lines changed: 3 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -71,16 +71,6 @@ bool isDartComponent(/* ReactElement|ReactComponent|Element */ instance) {
7171
return _getInternal(instance) != null;
7272
}
7373

74-
@JS('Object.keys')
75-
external Iterable _objectKeys(object);
76-
77-
/// Returns a Dart Map copy of the JS property key-value pairs in [jsMap].
78-
Map _dartifyJsMap(jsMap) {
79-
return new Map.fromIterable(_objectKeys(jsMap),
80-
value: (key) => getProperty(jsMap, key)
81-
);
82-
}
83-
8474
/// Returns the props for a [ReactElement] or composite [ReactComponent] [instance],
8575
/// shallow-converted to a Dart Map for convenience.
8676
///
@@ -90,15 +80,7 @@ Map _dartifyJsMap(jsMap) {
9080
/// __Deprecated. Use [getProps] instead. Will be removed in 2.0.0.__
9181
@deprecated
9282
Map getJsProps(/* ReactElement|ReactComponent */ instance) {
93-
var props = _dartifyJsMap(instance.props);
94-
95-
// Convert the nested style map so it can be read by Dart code.
96-
var style = props['style'];
97-
if (style != null) {
98-
props['style'] = _dartifyJsMap(style);
99-
}
100-
101-
return props;
83+
return unconvertJsProps(instance);
10284
}
10385

10486
/// Whether [Expando]s can be used on [ReactElement]s.
@@ -131,7 +113,7 @@ final Expando<UnmodifiableMapView> _elementPropsCache = _canUseExpandoOnReactEle
131113
/// Returns an unmodifiable Map view of props for a [ReactElement] or composite [ReactComponent] [instance].
132114
///
133115
/// For a native Dart component, this returns its [react.Component.props] in an unmodifiable Map view.
134-
/// For a JS component, this returns the result of [getJsProps] in an unmodifiable Map view.
116+
/// For a JS component, this returns the result of [unconvertJsProps] in an unmodifiable Map view.
135117
///
136118
/// If [traverseWrappers] is `true` then it will return an unmodifiable Map view of props of the first non-"Wrapper"
137119
/// instance.
@@ -170,7 +152,7 @@ Map getProps(/* ReactElement|ReactComponent */ instance, {bool traverseWrappers:
170152
if (cachedView != null) return cachedView;
171153
}
172154

173-
var propsMap = isDartComponent(instance) ? _getExtendedProps(instance) : getJsProps(instance);
155+
var propsMap = isDartComponent(instance) ? _getExtendedProps(instance) : unconvertJsProps(instance);
174156
var view = new UnmodifiableMapView(propsMap);
175157

176158
if (_elementPropsCache != null && !isCompositeComponent) {

pubspec.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ dependencies:
1616
logging: ">=0.11.3+2 <1.0.0"
1717
meta: ^1.1.6
1818
path: ^1.5.1
19-
react: ^4.4.2
19+
react: ^4.6.0
2020
source_span: ^1.4.1
2121
transformer_utils: ^0.1.5
2222
w_common: ^1.13.0

test/over_react/component_declaration/component_base_test.dart

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -969,7 +969,7 @@ main() {
969969
});
970970
}
971971

972-
dynamic getJsChildren(instance) => getJsProps(instance)['children'];
972+
dynamic getJsChildren(instance) => unconvertJsProps(instance)['children'];
973973

974974
dynamic getDartChildren(var renderedInstance) {
975975
assert(isDartComponent(renderedInstance));

test/over_react/util/react_wrappers_test.dart

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -50,8 +50,8 @@ main() {
5050
// If these objects are equal, then they proxy the same JS props object.
5151
expect(clone.props, isNot(equals(original.props)));
5252

53-
Map originalProps = getJsProps(original);
54-
Map cloneProps = getJsProps(clone);
53+
Map originalProps = unconvertJsProps(original);
54+
Map cloneProps = unconvertJsProps(clone);
5555

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

67-
Map originalProps = getJsProps(original);
68-
Map cloneProps = getJsProps(clone);
67+
Map originalProps = unconvertJsProps(original);
68+
Map cloneProps = unconvertJsProps(clone);
6969

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

108-
Map cloneProps = getJsProps(clone);
108+
Map cloneProps = unconvertJsProps(clone);
109109

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

198198
var renderedClone = react_test_utils.renderIntoDocument(clone);
199-
Map cloneProps = getJsProps(renderedClone);
199+
Map cloneProps = unconvertJsProps(renderedClone);
200200

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

284-
Map cloneProps = getJsProps(clone);
284+
Map cloneProps = unconvertJsProps(clone);
285285

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

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

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

0 commit comments

Comments
 (0)