Commit a3a23823 authored by Hixie's avatar Hixie

fn3: GlobalKey registration progress

Remove the "update" notification logic.
Hook the register/unregister functions. We're still not notifying.
parent c3b3b71b
...@@ -44,7 +44,6 @@ class ObjectKey extends Key { ...@@ -44,7 +44,6 @@ class ObjectKey extends Key {
int get hashCode => identityHashCode(value); int get hashCode => identityHashCode(value);
} }
typedef void GlobalKeyUpdateListener(GlobalKey key, Element element);
typedef void GlobalKeyRemoveListener(GlobalKey key); typedef void GlobalKeyRemoveListener(GlobalKey key);
/// A GlobalKey is one that must be unique across the entire application. It is /// A GlobalKey is one that must be unique across the entire application. It is
...@@ -59,12 +58,9 @@ abstract class GlobalKey extends Key { ...@@ -59,12 +58,9 @@ abstract class GlobalKey extends Key {
static final Map<GlobalKey, Element> _registry = new Map<GlobalKey, Element>(); static final Map<GlobalKey, Element> _registry = new Map<GlobalKey, Element>();
static final Map<GlobalKey, int> _debugDuplicates = new Map<GlobalKey, int>(); static final Map<GlobalKey, int> _debugDuplicates = new Map<GlobalKey, int>();
static final Map<GlobalKey, Set<GlobalKeyUpdateListener>> _updateListeners = new Map<GlobalKey, Set<GlobalKeyUpdateListener>>();
static final Map<GlobalKey, Set<GlobalKeyRemoveListener>> _removeListeners = new Map<GlobalKey, Set<GlobalKeyRemoveListener>>(); static final Map<GlobalKey, Set<GlobalKeyRemoveListener>> _removeListeners = new Map<GlobalKey, Set<GlobalKeyRemoveListener>>();
static final Set<GlobalKey> _updatedKeys = new Set<GlobalKey>();
static final Set<GlobalKey> _removedKeys = new Set<GlobalKey>(); static final Set<GlobalKey> _removedKeys = new Set<GlobalKey>();
// TODO(ianh): call this
void _register(Element element) { void _register(Element element) {
assert(() { assert(() {
if (_registry.containsKey(this)) { if (_registry.containsKey(this)) {
...@@ -77,7 +73,6 @@ abstract class GlobalKey extends Key { ...@@ -77,7 +73,6 @@ abstract class GlobalKey extends Key {
_registry[this] = element; _registry[this] = element;
} }
// TODO(ianh): call this
void _unregister(Element element) { void _unregister(Element element) {
assert(() { assert(() {
if (_registry.containsKey(this) && _debugDuplicates.containsKey(this)) { if (_registry.containsKey(this) && _debugDuplicates.containsKey(this)) {
...@@ -97,28 +92,6 @@ abstract class GlobalKey extends Key { ...@@ -97,28 +92,6 @@ abstract class GlobalKey extends Key {
} }
} }
// TODO(ianh): call this
void _didUpdate() {
_updatedKeys.add(this);
}
static void registerUpdateListener(GlobalKey key, GlobalKeyUpdateListener listener) {
assert(key != null);
Set<GlobalKeyUpdateListener> listeners =
_updateListeners.putIfAbsent(key, () => new Set<GlobalKeyUpdateListener>());
bool added = listeners.add(listener);
assert(added);
}
static void unregisterUpdateListener(GlobalKey key, GlobalKeyUpdateListener listener) {
assert(key != null);
assert(_updateListeners.containsKey(key));
bool removed = _updateListeners[key].remove(listener);
if (_updateListeners[key].isEmpty)
_updateListeners.remove(key);
assert(removed);
}
static void registerRemoveListener(GlobalKey key, GlobalKeyRemoveListener listener) { static void registerRemoveListener(GlobalKey key, GlobalKeyRemoveListener listener) {
assert(key != null); assert(key != null);
Set<GlobalKeyRemoveListener> listeners = Set<GlobalKeyRemoveListener> listeners =
...@@ -153,17 +126,9 @@ abstract class GlobalKey extends Key { ...@@ -153,17 +126,9 @@ abstract class GlobalKey extends Key {
throw message; throw message;
return true; return true;
}); });
if (_updatedKeys.isEmpty && _removedKeys.isEmpty) if (_removedKeys.isEmpty)
return; return;
try { try {
for (GlobalKey key in _updatedKeys) {
Element element = _registry[key];
if (element != null && _updateListeners.containsKey(key)) {
Set<GlobalKeyUpdateListener> localListeners = new Set<GlobalKeyUpdateListener>.from(_updateListeners[key]);
for (GlobalKeyUpdateListener listener in localListeners)
listener(key, element);
}
}
for (GlobalKey key in _removedKeys) { for (GlobalKey key in _removedKeys) {
if (!_registry.containsKey(key) && _removeListeners.containsKey(key)) { if (!_registry.containsKey(key) && _removeListeners.containsKey(key)) {
Set<GlobalKeyRemoveListener> localListeners = new Set<GlobalKeyRemoveListener>.from(_removeListeners[key]); Set<GlobalKeyRemoveListener> localListeners = new Set<GlobalKeyRemoveListener>.from(_removeListeners[key]);
...@@ -173,7 +138,6 @@ abstract class GlobalKey extends Key { ...@@ -173,7 +138,6 @@ abstract class GlobalKey extends Key {
} }
} finally { } finally {
_removedKeys.clear(); _removedKeys.clear();
_updatedKeys.clear();
} }
} }
...@@ -545,6 +509,8 @@ abstract class Element<T extends Widget> implements BuildContext { ...@@ -545,6 +509,8 @@ abstract class Element<T extends Widget> implements BuildContext {
_parent = parent; _parent = parent;
_slot = newSlot; _slot = newSlot;
_depth = _parent != null ? _parent.depth + 1 : 1; _depth = _parent != null ? _parent.depth + 1 : 1;
if (widget.key is GlobalKey)
widget.key._register(this);
assert(() { _debugLifecycleState = _ElementLifecycle.mounted; return true; }); assert(() { _debugLifecycleState = _ElementLifecycle.mounted; return true; });
} }
...@@ -610,6 +576,8 @@ abstract class Element<T extends Widget> implements BuildContext { ...@@ -610,6 +576,8 @@ abstract class Element<T extends Widget> implements BuildContext {
assert(_debugLifecycleState == _ElementLifecycle.mounted); assert(_debugLifecycleState == _ElementLifecycle.mounted);
assert(widget != null); assert(widget != null);
assert(depth != null); assert(depth != null);
if (widget.key is GlobalKey)
widget.key._unregister(this);
assert(() { _debugLifecycleState = _ElementLifecycle.defunct; return true; }); assert(() { _debugLifecycleState = _ElementLifecycle.defunct; return true; });
} }
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment