Proposal: Typed clearWhere
Preview of a class-scoped clearWhere(Class, predicate) overload in @blac/core, so session-boundary resets get typed args instead of optional chaining.
Problem
clearWhere(predicate) visits every live instance of every class, so the predicate receives an untyped container. Most predicates written while migrating reset events are scoped to one class, and they all repeat the same shape:
clearWhere( (bloc) => bloc instanceof ChannelCubit && bloc.args?.workspaceId === id,);The instanceof check is easy to forget, which widens the reset to every class with a matching workspaceId. The optional chaining hides typos in arg names.
Proposed API
clearWhere(ChannelCubit, (bloc) => bloc.args.workspaceId === id);- Only instances of
ChannelCubitare visited. blocis typed asChannelCubit, soargsis checked against the class.- Everything else matches the existing form: matches are collected before any is disposed, and
keepAliveinstances and ones with owners are disposed too.
Library change
clearWheregains an overload whose class form only passes instances of that class to the predicate. About 10 lines.- Tests: only the given class is visited, other classes with matching args are untouched.
- Docs: one example in Instance Management.
Effort: about 1 hour.
Open questions
- Should the class form also accept an array of classes, for a reset that spans a few related containers?