-
Notifications
You must be signed in to change notification settings - Fork 58
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
UIP-2161 Implement DisposableManagerV3 for UiComponent #91
Changes from 4 commits
94262e2
6374a60
d62e5e3
542bd57
c8a2e06
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 |
---|---|---|
|
@@ -14,6 +14,8 @@ | |
|
||
library over_react.component_declaration.component_base; | ||
|
||
import 'dart:async'; | ||
|
||
import 'package:meta/meta.dart'; | ||
import 'package:over_react/over_react.dart' show | ||
ClassNameBuilder, | ||
|
@@ -31,6 +33,7 @@ import 'package:over_react/src/component_declaration/component_type_checking.dar | |
import 'package:over_react/src/util/ddc_emulated_function_name_bug.dart' as ddc_emulated_function_name_bug; | ||
import 'package:react/react.dart' as react; | ||
import 'package:react/react_client.dart'; | ||
import 'package:w_common/disposable.dart'; | ||
|
||
export 'package:over_react/src/component_declaration/component_type_checking.dart' show isComponentOfType, isValidElementOfType; | ||
|
||
|
@@ -94,8 +97,12 @@ typedef TProps BuilderOnlyUiFactory<TProps extends UiProps>(); | |
/// | ||
/// Extends [react.Component]. | ||
/// | ||
/// Implements [DisposableManagerV3] | ||
/// | ||
/// Related: [UiStatefulComponent] | ||
abstract class UiComponent<TProps extends UiProps> extends react.Component { | ||
abstract class UiComponent<TProps extends UiProps> extends react.Component implements DisposableManagerV3 { | ||
Disposable _disposableProxy; | ||
|
||
/// The props for the non-forwarding props defined in this component. | ||
Iterable<ConsumedProps> get consumedProps => null; | ||
|
||
|
@@ -156,6 +163,12 @@ abstract class UiComponent<TProps extends UiProps> extends react.Component { | |
validateRequiredProps(props); | ||
} | ||
|
||
@override | ||
@mustCallSuper | ||
void componentWillUnmount() { | ||
_disposableProxy?.dispose(); | ||
} | ||
|
||
|
||
// ---------------------------------------------------------------------- | ||
// ---------------------------------------------------------------------- | ||
|
@@ -199,6 +212,61 @@ abstract class UiComponent<TProps extends UiProps> extends react.Component { | |
// END Typed props helpers | ||
// ---------------------------------------------------------------------- | ||
// ---------------------------------------------------------------------- | ||
|
||
// ---------------------------------------------------------------------- | ||
// ---------------------------------------------------------------------- | ||
// BEGIN DisposableManagerV3 interface implementation | ||
// | ||
|
||
@override | ||
Future<T> awaitBeforeDispose<T>(Future<T> future) => | ||
_getDisposableProxy().awaitBeforeDispose<T>(future); | ||
|
||
@override | ||
Future<T> getManagedDelayedFuture<T>(Duration duration, T callback()) => | ||
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 we make the callback param covariant? |
||
_getDisposableProxy().getManagedDelayedFuture<T>(duration, callback); | ||
|
||
@override | ||
Timer getManagedPeriodicTimer(Duration duration, void callback(Timer timer)) => | ||
_getDisposableProxy().getManagedPeriodicTimer(duration, callback); | ||
|
||
@override | ||
Timer getManagedTimer(Duration duration, void callback()) => | ||
_getDisposableProxy().getManagedTimer(duration, callback); | ||
|
||
@override | ||
Completer<T> manageCompleter<T>(Completer<T> completer) => | ||
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 we make the parameter covariant? |
||
_getDisposableProxy().manageCompleter<T>(completer); | ||
|
||
@override | ||
void manageDisposable(Disposable disposable) => | ||
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 we make the parameter covariant? |
||
_getDisposableProxy().manageDisposable(disposable); | ||
|
||
@override | ||
void manageDisposer(Disposer disposer) => | ||
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 we make the parameter covariant? 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. I am unsure if/how inheritance would work in the case of typedefs. Does covariant make sense in that case? 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. oh... didn't realize |
||
_getDisposableProxy().manageDisposer(disposer); | ||
|
||
@override | ||
void manageStreamController(StreamController controller) => | ||
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 we make the parameter covariant? |
||
_getDisposableProxy().manageStreamController(controller); | ||
|
||
@override | ||
void manageStreamSubscription(StreamSubscription subscription) => | ||
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 we make the parameter covariant? |
||
_getDisposableProxy().manageStreamSubscription(subscription); | ||
|
||
/// Instantiates a new [Disposable] instance on the first call to the | ||
/// [DisposableManagerV3] method. | ||
Disposable _getDisposableProxy() { | ||
if (_disposableProxy == null) { | ||
_disposableProxy = new Disposable(); | ||
} | ||
return _disposableProxy; | ||
} | ||
|
||
// | ||
// END DisposableManagerV3 interface implementation | ||
// ---------------------------------------------------------------------- | ||
// ---------------------------------------------------------------------- | ||
} | ||
|
||
/// The basis for a stateful over_react component. | ||
|
@@ -248,7 +316,7 @@ abstract class UiStatefulComponent<TProps extends UiProps, TState extends UiStat | |
TState newState() => typedStateFactory({}); | ||
|
||
// | ||
// END Typed state helpers | ||
// END Typed props helpers | ||
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. Looks like this got changed accidentally 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. 😰 |
||
// ---------------------------------------------------------------------- | ||
// ---------------------------------------------------------------------- | ||
} | ||
|
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.
should this pull in w_common/disposable_browser.dart instead of just disposable.dart?
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.
+1
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.
It is dependent on updating the the DisposableManager interface to include the new browser specific utility functions.
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.
I have created RAP-2130 to address this.