-
Notifications
You must be signed in to change notification settings - Fork 57
AF-2937 Add hooks to support tracing #195
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
67a7a92
0a7f393
0503e01
18a1a3a
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -151,33 +151,62 @@ abstract class _FluxComponentMixin<TProps extends FluxUiProps> implements Batche | |
| /// These subscriptions are canceled when the component is unmounted. | ||
| List<StreamSubscription> _subscriptions = []; | ||
|
|
||
| // This is private and called by classes to work around super-calls not being supported in mixins | ||
| void _componentWillMount() { | ||
| /// Subscribe to all applicable stores. | ||
| /// | ||
| /// [Store]s returned by [redrawOn] will have their triggers mapped directly to this components | ||
| /// redraw function. | ||
| /// | ||
| /// [Store]s included in the [getStoreHandlers] result will be listened to and wired up to their | ||
| /// respective handlers. | ||
| Map<Store, StoreHandler> handlers = new Map.fromIterable(redrawOn(), | ||
| value: (_) => (_) => redraw())..addAll(getStoreHandlers()); | ||
|
|
||
| handlers.forEach((store, handler) { | ||
| String message = 'Cannot listen to a disposed/disposing Store.'; | ||
|
|
||
| var isDisposedOrDisposing = store.isOrWillBeDisposed ?? false; | ||
|
|
||
| assert(!isDisposedOrDisposing, '$message This can be caused by BatchedRedraws ' | ||
| void _validateStoreDisposalState(Store store) { | ||
| String message = 'Cannot listen to a disposed/disposing Store.'; | ||
|
|
||
| var isDisposedOrDisposing = store.isOrWillBeDisposed ?? false; | ||
|
|
||
| assert(!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 (isDisposedOrDisposing) _logger.warning(message); | ||
| if (isDisposedOrDisposing) _logger.warning(message); | ||
| } | ||
|
|
||
| // This is private and called by classes to work around super-calls not being supported in mixins | ||
| void _componentWillMount() { | ||
| // Subscribe to all applicable stores. | ||
| // | ||
| // Stores returned by `redrawOn()` will have their triggers mapped directly | ||
| // to `handleRedrawOn`, which invokes this component's redraw function. | ||
| // | ||
| // Stores included in the `getStoreHandlers()` result will be listened to | ||
| // and wired up to their respective handlers. | ||
| final customStoreHandlers = getStoreHandlers(); | ||
| final storesWithoutCustomHandlers = redrawOn().where((store) => !customStoreHandlers.containsKey(store)); | ||
|
|
||
| customStoreHandlers.forEach((store, handler) { | ||
| _validateStoreDisposalState(store); | ||
| StreamSubscription subscription = store.listen(handler); | ||
| _subscriptions.add(subscription); | ||
| }); | ||
| storesWithoutCustomHandlers.forEach(listenToStoreForRedraw); | ||
| } | ||
|
|
||
| /// Used to register [handleRedrawOn] as a listener for the given [store]. | ||
| /// | ||
| /// Called for each of the stores returned by [redrawOn] that don't have custom | ||
| /// store handlers (defined in [getStoreHandlers]). | ||
| /// | ||
| /// Override to set up custom listener behavior. | ||
| @protected | ||
| void listenToStoreForRedraw(Store store) { | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Should this have
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Good question. No, since there are some cases where the listening setup might use a different mechanism. Here's an example override @override
void listenToStoreForRedraw(Store store) {
if (store is TracedStore) {
listenToStream(store.streamWithPayload, handleRedrawOnWithPayload);
} else {
super.listenToStoreForRedraw(store);
}
} |
||
| _validateStoreDisposalState(store); | ||
| _subscriptions.add(store.listen(handleRedrawOn)); | ||
| } | ||
|
|
||
| /// Redraws the component for a given [store]. | ||
| /// | ||
| /// Called whenever an event is emitted by one of the stores returned by | ||
| /// [redrawOn] that don't have custom store handlers (defined in | ||
| /// [getStoreHandlers]). | ||
| /// | ||
| /// Override and call super to add custom behavior. | ||
| @mustCallSuper | ||
| @protected | ||
| void handleRedrawOn(Store store) { | ||
| redraw(); | ||
| } | ||
|
|
||
| // This is private and called by classes to work around super-calls not being supported in mixins | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,28 @@ | ||
| part of over_react.component_declaration.flux_component_test; | ||
|
|
||
| @Factory() | ||
| UiFactory<TestHandlerLifecycleProps> TestHandlerLifecycle; | ||
|
|
||
| @Props() | ||
| class TestHandlerLifecycleProps extends FluxUiProps<TestActions, TestStore> {} | ||
|
|
||
| @Component() | ||
| class TestHandlerLifecycleComponent extends FluxUiComponent<TestHandlerLifecycleProps> { | ||
| List<List<dynamic>> lifecycleCalls = []; | ||
|
|
||
| @override | ||
| void handleRedrawOn(Store store) { | ||
| lifecycleCalls.add(['handleRedrawOn', store]); | ||
| super.handleRedrawOn(store); | ||
| } | ||
|
|
||
| @override | ||
| void listenToStoreForRedraw(Store store) { | ||
| lifecycleCalls.add(['listenToStoreForRedraw', store]); | ||
| super.listenToStoreForRedraw(store); | ||
| } | ||
|
|
||
| @override | ||
| render() => Dom.div()(); | ||
| } | ||
|
|
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,31 @@ | ||
| part of over_react.component_declaration.flux_component_test; | ||
|
|
||
| @Factory() | ||
| UiFactory<TestStatefulHandlerLifecycleProps> TestStatefulHandlerLifecycle; | ||
|
|
||
| @Props() | ||
| class TestStatefulHandlerLifecycleProps extends FluxUiProps<TestActions, TestStore> implements TestHandlerLifecycleProps {} | ||
|
|
||
| @State() | ||
| class TestStatefulHandlerLifecycleState extends UiState {} | ||
|
|
||
| @Component() | ||
| class TestStatefulHandlerLifecycleComponent extends FluxUiStatefulComponent<TestStatefulHandlerLifecycleProps, TestStatefulHandlerLifecycleState> { | ||
| List<List<dynamic>> lifecycleCalls = []; | ||
|
|
||
| @override | ||
| void handleRedrawOn(Store store) { | ||
| lifecycleCalls.add(['handleRedrawOn', store]); | ||
| super.handleRedrawOn(store); | ||
| } | ||
|
|
||
| @override | ||
| void listenToStoreForRedraw(Store store) { | ||
| lifecycleCalls.add(['listenToStoreForRedraw', store]); | ||
| super.listenToStoreForRedraw(store); | ||
| } | ||
|
|
||
| @override | ||
| render() => Dom.div()(); | ||
| } | ||
|
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Whitespace-agnostic diff in this file may help when reviewing