Instead of creating multiple Observers for a single watched state, cache them. Because the cache is a hard ref, it replaces the hardRef set from before.
Note that this has one change to behavior: if you create an Observer but never call :onChange, it will never clean up. This is because we create the hardRef upon init, so that objects can be shared. Cleanup still occurs when all change listeners are disconnected, but if you never create any to disconnect that can't occur. However, I don't see this being an issue since Observers are never created without using their one and only purpose of connecting :onChange.
Instead of creating multiple
Observer
s for a single watched state, cache them. Because the cache is a hard ref, it replaces the hardRef set from before.Note that this has one change to behavior: if you create an
Observer
but never call:onChange
, it will never clean up. This is because we create the hardRef upon init, so that objects can be shared. Cleanup still occurs when all change listeners are disconnected, but if you never create any to disconnect that can't occur. However, I don't see this being an issue sinceObserver
s are never created without using their one and only purpose of connecting:onChange
.