Skip to content

Commit 2657d6c

Browse files
committed
Merge pull request #236 from cleandart/CPLAT-8698-expose-componentZone
CPLAT-8698 Expose the componentZone
2 parents 78ce0f4 + 86434e3 commit 2657d6c

File tree

2 files changed

+16
-5
lines changed

2 files changed

+16
-5
lines changed

lib/react_client.dart

Lines changed: 16 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ import 'dart:js';
1313
import 'dart:js_util';
1414

1515
import "package:js/js.dart";
16+
import 'package:meta/meta.dart';
1617

1718
import "package:react/react.dart";
1819
import 'package:react/react_client/js_interop_helpers.dart';
@@ -53,6 +54,21 @@ dynamic listifyChildren(dynamic children) {
5354
}
5455
}
5556

57+
/// The zone in which React will call component lifecycle methods.
58+
///
59+
/// This can be used to sync a test's zone and React's component zone, ensuring that component prop callbacks and
60+
/// lifecycle method output all occurs within the same zone as the test.
61+
///
62+
/// __Example:__
63+
///
64+
/// test('zone test', () {
65+
/// componentZone = Zone.current;
66+
///
67+
/// // ... test your component
68+
/// }
69+
@visibleForTesting
70+
Zone componentZone = Zone.root;
71+
5672
/// Use [ReactDartComponentFactoryProxy2] instead.
5773
///
5874
/// Will be removed when [Component] is removed in the `6.0.0` release.
@@ -473,10 +489,6 @@ final ReactDartInteropStatics _dartInteropStatics = (() {
473489
})();
474490

475491
abstract class _ReactDartInteropStatics2 {
476-
// TODO 3.1.0-wip expose for testing?
477-
/// The zone in which all component lifecycle methods are run.
478-
static final componentZone = Zone.root;
479-
480492
static void _updatePropsAndStateWithJs(Component2 component, JsMap props, JsMap state) {
481493
component
482494
..props = new JsBackedMap.backedBy(props)

test/lifecycle_test.dart

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,6 @@ import 'package:react/react.dart' as react;
1414
import 'package:react/react_client.dart';
1515
import 'package:react/react_client/js_backed_map.dart';
1616
import 'package:react/react_client/react_interop.dart' as react_interop;
17-
import 'package:react/react_client/react_interop.dart';
1817
import 'package:react/react_dom.dart' as react_dom;
1918
import 'package:react/react_test_utils.dart' as react_test_utils;
2019
import 'package:test/test.dart';

0 commit comments

Comments
 (0)