diff --git a/lib/src/component_declaration/flux_component.dart b/lib/src/component_declaration/flux_component.dart index 09d1c938a..f334caec2 100644 --- a/lib/src/component_declaration/flux_component.dart +++ b/lib/src/component_declaration/flux_component.dart @@ -15,6 +15,7 @@ library over_react.component_declaration.flux_component; import 'dart:async'; +import 'package:logging/logging.dart'; import 'package:w_flux/w_flux.dart'; import './annotations.dart' as annotations; import './transformer_helpers.dart'; @@ -82,6 +83,7 @@ abstract class FluxUiStatefulComponent implements BatchedRedraws { + static final Logger _logger = new Logger('_FluxComponentMixin'); TProps get props; /// List of store subscriptions created when the component mounts. @@ -101,6 +103,14 @@ abstract class _FluxComponentMixin implements Batche value: (_) => (_) => redraw())..addAll(getStoreHandlers()); handlers.forEach((store, handler) { + String message = 'Cannot listen to a disposed/disposing Store.'; + assert(!store.isDisposedOrDisposing, '$message This can be caused by BatchedRedraws ' + 'mounting the component asynchronously after the store has been disposed. If you are ' + 'in a test environment, try adding an `await window.animationFrame;` before disposing your ' + 'store.'); + + if (store.isDisposedOrDisposing) _logger.warning(message); + StreamSubscription subscription = store.listen(handler); _subscriptions.add(subscription); }); diff --git a/pubspec.yaml b/pubspec.yaml index 93b0b45ba..62f6a22b9 100644 --- a/pubspec.yaml +++ b/pubspec.yaml @@ -10,6 +10,7 @@ dependencies: analyzer: ">=0.30.0 <0.31.0" barback: "^0.15.0" js: "^0.6.0" + logging: ">=0.11.3+1 <1.0.0" meta: "^1.0.4" path: "^1.4.1" react: "^3.1.0"