@@ -20,13 +20,13 @@ import 'dart:html';
2020import 'dart:js_util' as js_util;
2121
2222import 'package:js/js.dart' ;
23- import 'package:memoize/memoize.dart' ;
2423import 'package:meta/meta.dart' ;
2524import 'package:over_react/component_base.dart' ;
2625import 'package:over_react/src/component_declaration/annotations.dart' ;
2726import 'package:over_react/src/component_declaration/builder_helpers.dart' as builder_helpers;
2827import 'package:over_react/src/component_declaration/component_type_checking.dart' ;
2928import 'package:over_react/src/util/context.dart' ;
29+ import 'package:over_react/src/util/dart_value_wrapper.dart' ;
3030import 'package:over_react/src/util/equality.dart' ;
3131import 'package:react/react_client.dart' ;
3232import 'package:react/react_client/js_backed_map.dart' ;
@@ -35,6 +35,10 @@ import 'package:redux/redux.dart';
3535
3636part 'over_react_redux.over_react.g.dart' ;
3737
38+ // Notes:
39+ //
40+ // [1] This value could be either a raw value or a value wrapped in DartValueWrapper.
41+
3842/// This class is present:
3943///
4044/// 1. to allow for consumers which have used the --backwards-compat flag with over_react_codemod to statically analyze:
@@ -200,47 +204,47 @@ UiFactory<TProps> Function(UiFactory<TProps>) connect<TReduxState, TProps extend
200204 return interopFunction;
201205 }
202206
203- JsMap handleMapStateToProps (ReactInteropValue jsState) {
207+ JsMap handleMapStateToProps (Object /*[1]*/ jsState) {
204208 return jsMapFromProps (
205209 mapStateToProps (
206- unwrapInteropValue (jsState),
210+ DartValueWrapper . unwrapIfNeeded (jsState),
207211 ),
208212 );
209213 }
210214
211- JsMap handleMapStateToPropsWithOwnProps (ReactInteropValue jsState, JsMap jsOwnProps) {
215+ JsMap handleMapStateToPropsWithOwnProps (Object /*[1]*/ jsState, JsMap jsOwnProps) {
212216 return jsMapFromProps (
213217 mapStateToPropsWithOwnProps (
214- unwrapInteropValue (jsState),
218+ DartValueWrapper . unwrapIfNeeded (jsState),
215219 jsPropsToTProps (jsOwnProps),
216220 ),
217221 );
218222 }
219223
220- JsMap Function (ReactInteropValue jsState) handleMakeMapStateToProps (ReactInteropValue initialJsState, JsMap initialJsOwnProps) {
224+ JsMap Function (Object /*[1]*/ jsState) handleMakeMapStateToProps (Object /*[1]*/ initialJsState, JsMap initialJsOwnProps) {
221225 var mapToFactory = makeMapStateToProps (
222- unwrapInteropValue (initialJsState),
226+ DartValueWrapper . unwrapIfNeeded (initialJsState),
223227 jsPropsToTProps (initialJsOwnProps)
224228 );
225- JsMap handleMakeMapStateToPropsFactory (ReactInteropValue jsState) {
229+ JsMap handleMakeMapStateToPropsFactory (Object /*[1]*/ jsState) {
226230 return jsMapFromProps (
227231 mapToFactory (
228- unwrapInteropValue (jsState),
232+ DartValueWrapper . unwrapIfNeeded (jsState),
229233 ),
230234 );
231235 }
232236 return allowInteropWithArgCount (handleMakeMapStateToPropsFactory, 1 );
233237 }
234238
235- JsMap Function (ReactInteropValue jsState, JsMap jsOwnProps) handleMakeMapStateToPropsWithOwnProps (ReactInteropValue initialJsState, JsMap initialJsOwnProps) {
239+ JsMap Function (Object /*[1]*/ jsState, JsMap jsOwnProps) handleMakeMapStateToPropsWithOwnProps (Object /*[1]*/ initialJsState, JsMap initialJsOwnProps) {
236240 var mapToFactory = makeMapStateToPropsWithOwnProps (
237- unwrapInteropValue (initialJsState),
241+ DartValueWrapper . unwrapIfNeeded (initialJsState),
238242 jsPropsToTProps (initialJsOwnProps)
239243 );
240- JsMap handleMakeMapStateToPropsWithOwnPropsFactory (ReactInteropValue jsState, JsMap jsOwnProps) {
244+ JsMap handleMakeMapStateToPropsWithOwnPropsFactory (Object /*[1]*/ jsState, JsMap jsOwnProps) {
241245 return jsMapFromProps (
242246 mapToFactory (
243- unwrapInteropValue (jsState),
247+ DartValueWrapper . unwrapIfNeeded (jsState),
244248 jsPropsToTProps (jsOwnProps),
245249 ),
246250 );
@@ -304,8 +308,8 @@ UiFactory<TProps> Function(UiFactory<TProps>) connect<TReduxState, TProps extend
304308 );
305309 }
306310
307- bool handleAreStatesEqual (ReactInteropValue jsNext, ReactInteropValue jsPrev) =>
308- areStatesEqual (unwrapInteropValue (jsNext), unwrapInteropValue (jsPrev));
311+ bool handleAreStatesEqual (Object /*[1]*/ jsNext, Object /*[1]*/ jsPrev) =>
312+ areStatesEqual (DartValueWrapper . unwrapIfNeeded (jsNext), DartValueWrapper . unwrapIfNeeded (jsPrev));
309313
310314 bool handleAreOwnPropsEqual (JsMap jsNext, JsMap jsPrev) =>
311315 areOwnPropsEqual (jsPropsToTProps (jsNext), jsPropsToTProps (jsPrev));
@@ -497,14 +501,9 @@ class ReactJsReactReduxComponentFactoryProxy extends ReactJsContextComponentFact
497501
498502/// Converts a Redux.dart [Store] into a Javascript object formatted for consumption by react-redux.
499503JsReactReduxStore _reduxifyStore (Store store) {
500- // Memoize this so that the same ReactInteropValue instances will be used
501- // for a given state, allowing JS `===` checks to not fail when the same
502- // state object is passed.
503- final memoizedWrapInteropValue = imemo1 (wrapInteropValue);
504-
505504 return JsReactReduxStore (
506505 getState: allowInterop (() {
507- return memoizedWrapInteropValue (store.state);
506+ return DartValueWrapper . wrapIfNeeded (store.state);
508507 }),
509508 subscribe: allowInterop ((cb) {
510509 return allowInterop (store.onChange.listen ((_){cb ();}).cancel);
@@ -527,7 +526,7 @@ class JsReactReduxStore {
527526 external Store get dartStore;
528527
529528 external factory JsReactReduxStore ({
530- ReactInteropValue Function () getState,
529+ Object /*[1]*/ Function () getState,
531530 Dispatcher dispatch,
532531 Function Function (Function ) subscribe,
533532 Store dartStore,
@@ -538,22 +537,22 @@ class JsReactReduxStore {
538537@JS ()
539538@anonymous
540539class JsConnectOptions {
541- external set areStatesEqual (bool Function (ReactInteropValue , ReactInteropValue ) value);
540+ external set areStatesEqual (bool Function (Object /*[1]*/ , Object /*[1]*/ ) value);
542541 external set areOwnPropsEqual (bool Function (JsMap , JsMap ) value);
543542 external set areStatePropsEqual (bool Function (JsMap , JsMap ) value);
544543 external set areMergedPropsEqual (bool Function (JsMap , JsMap ) value);
545544 external set forwardRef (bool value);
546545 external set pure (bool value);
547546 external set context (ReactContext value);
548- external bool Function (ReactInteropValue , ReactInteropValue ) get areStatesEqual;
547+ external bool Function (Object /*[1]*/ , Object /*[1]*/ ) get areStatesEqual;
549548 external bool Function (JsMap , JsMap ) get areOwnPropsEqual;
550549 external bool Function (JsMap , JsMap ) get areStatePropsEqual;
551550 external bool Function (JsMap , JsMap ) get areMergedPropsEqual;
552551 external bool get forwardRef;
553552 external bool get pure;
554553 external ReactContext get context;
555554 external factory JsConnectOptions ({
556- bool Function (ReactInteropValue , ReactInteropValue ) areStatesEqual,
555+ bool Function (Object /*[1]*/ , Object /*[1]*/ ) areStatesEqual,
557556 bool Function (JsMap , JsMap ) areOwnPropsEqual,
558557 bool Function (JsMap , JsMap ) areStatePropsEqual,
559558 bool Function (JsMap , JsMap ) areMergedPropsEqual,
@@ -563,17 +562,3 @@ class JsConnectOptions {
563562 });
564563}
565564
566- /// A wrapper class that prevents dart2js from jsifying [value] .
567- class ReactInteropValue {
568- dynamic value;
569- }
570-
571- /// A helper function that retrieves the [value] from a [ReactInteropValue] .
572- T unwrapInteropValue <T >(ReactInteropValue value) {
573- return value.value as T ;
574- }
575-
576- /// A helper function that wraps a [value] in a [ReactInteropValue] .
577- ReactInteropValue wrapInteropValue (dynamic value) {
578- return ReactInteropValue ()..value = value;
579- }
0 commit comments