Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(110)

Unified Diff: sky/framework/fn.dart

Issue 1027633003: [Effen] Add AnimatedComponent base class (Closed) Base URL: https://github.com/domokit/mojo.git@master
Patch Set: cr changes Created 5 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « sky/framework/editing/editable_text.dart ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: sky/framework/fn.dart
diff --git a/sky/framework/fn.dart b/sky/framework/fn.dart
index 5262227dd2f13be108cb997513cc0530880e0ea6..7aa23d59e684edd4cfe7f9478d564b645fcab449 100644
--- a/sky/framework/fn.dart
+++ b/sky/framework/fn.dart
@@ -645,8 +645,8 @@ bool _buildScheduled = false;
bool _inRenderDirtyComponents = false;
void _notifyMountStatusChanged() {
- _unmountedComponents.forEach((c) => c.didUnmount());
- _mountedComponents.forEach((c) => c.didMount());
+ _unmountedComponents.forEach((c) => c._didUnmount());
+ _mountedComponents.forEach((c) => c._didMount());
_mountedComponents.clear();
_unmountedComponents.clear();
}
@@ -700,6 +700,23 @@ abstract class Component extends Node {
static int _currentOrder = 0;
bool _stateful;
static Component _currentlyBuilding;
+ List<Function> _mountCallbacks;
+ List<Function> _unmountCallbacks;
+
+ void onDidMount(Function fn) {
+ if (_mountCallbacks == null)
+ _mountCallbacks = new List<Function>();
+
+ _mountCallbacks.add(fn);
+ }
+
+ void onDidUnmount(Function fn) {
+ if (_unmountCallbacks == null)
+ _unmountCallbacks = new List<Function>();
+
+ _unmountCallbacks.add(fn);
+ }
+
Component({ Object key, bool stateful })
: _stateful = stateful != null ? stateful : false,
@@ -709,8 +726,15 @@ abstract class Component extends Node {
Component.fromArgs(Object key, bool stateful)
: this(key: key, stateful: stateful);
- void didMount() {}
- void didUnmount() {}
+ void _didMount() {
+ if (_mountCallbacks != null)
+ _mountCallbacks.forEach((fn) => fn());
+ }
+
+ void _didUnmount() {
+ if (_unmountCallbacks != null)
+ _unmountCallbacks.forEach((fn) => fn());
+ }
// TODO(rafaelw): It seems wrong to expose DOM at all. This is presently
// needed to get sizing info.
« no previous file with comments | « sky/framework/editing/editable_text.dart ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698