Skip to content

Commit

Permalink
Merge pull request #72 from tomconnell-wf/do_not_listen_to_disposed_s…
Browse files Browse the repository at this point in the history
…tores

HY-4957 Alert devs about batchedRedraw race condition, and log if it happens in prod. ⚠️
  • Loading branch information
greglittlefield-wf authored Jun 14, 2017
2 parents e3dbef1 + 1c5f5a2 commit 4e898ff
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 0 deletions.
10 changes: 10 additions & 0 deletions lib/src/component_declaration/flux_component.dart
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand Down Expand Up @@ -82,6 +83,7 @@ abstract class FluxUiStatefulComponent<TProps extends FluxUiProps, TState extend
///
/// Private so it will only get used in this file, since having lifecycle methods in a mixin is risky.
abstract class _FluxComponentMixin<TProps extends FluxUiProps> implements BatchedRedraws {
static final Logger _logger = new Logger('_FluxComponentMixin');
TProps get props;

/// List of store subscriptions created when the component mounts.
Expand All @@ -101,6 +103,14 @@ abstract class _FluxComponentMixin<TProps extends FluxUiProps> 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);
});
Expand Down
1 change: 1 addition & 0 deletions pubspec.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down

0 comments on commit 4e898ff

Please sign in to comment.