@@ -228,26 +228,21 @@ mixin _WatchAdapter<T extends DataModelMixin<T>> on _RemoteAdapter<T> {
228228
229229 // closure to get latest model and watchable relationship pairs
230230 T ? _getUpdatedModel () {
231- final model = findOneLocal (key);
232- if (model != null ) {
233- // get all metas provided via `alsoWatch`
234- final metas = alsoWatch
235- ? .call (RelationshipGraphNode <T >())
236- .whereType <RelationshipMeta >();
237-
238- // recursively get applicable watch key pairs for each meta -
239- // from top to bottom (e.g. `p`, `p.familia`, `p.familia.cottage`)
240- if (metas != null ) {
241- alsoWatchPairs = metas
242- .map ((meta) => _getPairsForMeta (meta._top, model._key! ))
243- .expand ((e) => e)
244- .toSet ();
245- }
246- } else {
247- // if there is no model nothing should be watched, reset pairs
248- alsoWatchPairs = {};
231+ // get all metas provided via `alsoWatch`
232+ final metas = alsoWatch
233+ ? .call (RelationshipGraphNode <T >())
234+ .whereType <RelationshipMeta >();
235+
236+ // recursively get applicable watch key pairs for each meta -
237+ // from top to bottom (e.g. `p`, `p.familia`, `p.familia.cottage`)
238+ if (metas != null ) {
239+ alsoWatchPairs = metas
240+ .map ((meta) => _getPairsForMeta (meta._top, key))
241+ .expand ((e) => e)
242+ .toSet ();
249243 }
250- return model;
244+
245+ return findOneLocal (key);
251246 }
252247
253248 final notifier = DataStateNotifier <T ?>(
@@ -320,14 +315,13 @@ mixin _WatchAdapter<T extends DataModelMixin<T>> on _RemoteAdapter<T> {
320315 // of `andEach` even seemingly unrelated models could trigger)
321316 bufferModel = _getUpdatedModel ();
322317
323- key = bufferModel? ._key ?? key;
324-
325318 for (final event in events) {
326319 if (event.keys.contains (key)) {
327320 // handle done loading
328321 if (notifier.data.isLoading &&
329- event.keys.last == label.toString () &&
330- event.type == DataGraphEventType .doneLoading) {
322+ event.keys.last == label.toString () &&
323+ event.type == DataGraphEventType .doneLoading ||
324+ event.type == DataGraphEventType .removeEdge) {
331325 states
332326 .add (DataState (bufferModel, isLoading: false , exception: null ));
333327 }
@@ -344,13 +338,6 @@ mixin _WatchAdapter<T extends DataModelMixin<T>> on _RemoteAdapter<T> {
344338 ));
345339 }
346340 }
347-
348- // temporarily restore removed pair so that watchedRelationshipUpdate
349- // has a chance to apply the update
350- if (event.type == DataGraphEventType .removeEdge &&
351- ! event.keys.first.startsWith ('id:' )) {
352- alsoWatchPairs.add ((event.keys.first, event.keys.last));
353- }
354341 }
355342
356343 // handle deletion
@@ -405,6 +392,9 @@ mixin _WatchAdapter<T extends DataModelMixin<T>> on _RemoteAdapter<T> {
405392 // `S` could be `T` or `List<T>`
406393 void _updateFromStates <S >(
407394 List <DataState <S >> states, DataStateNotifier <S > notifier) {
395+ if (states.isEmpty) {
396+ return ;
397+ }
408398 // calculate final state & drain
409399 final mergedState = states.fold <DataState <S >?>(null , (acc, state) {
410400 return acc == null ? state : acc.merge (state);
0 commit comments