-
Notifications
You must be signed in to change notification settings - Fork 5
ModuleManager
The module manager will take care of building modules and tracking living ones, keeping them alive for as long as the viewController associated with them is used.
The modules will be kept alive using the Flyweight (hash consing) design pattern. A Weak dictionary will have a weak reference to the viewController associated with the module as key and a strong reference to the module itself as value. When the view controller reference becomes nil because it is no longer retained by UIKit, the module will be deallocated as well.
The Flyweight design pattern is implemented using LNZWeakCollection
to have Dictionaries with weak keys and strong values (or vice versa).
NSHashTable
was used at the beginning, but the release of weak references is done by this object only when the data structure requires resizing. The module was kept alive for longer than it was needed. LNZWeakCollection
kills the dead reference almost immediately (exactly at the next usage of the instance of the data structure).
The module manager cannot build modules. This duty is left to a ModuleMaking object wrapped in a ModuleRoutingStep
.
When a new module is created from a ModuleRoutingStep
(or from a Deeplink) the module manager will direct all registered events listeners to subscribe to interesting events.