This package provides a simple call-stack context provision.
Usage
; ; // name is optional; ;contextProvidedFn;
Context's require()
will throw an error if the context has not been provided.
Name your context at construction time so that you get a meaningful error
message.
Providing several contexts
Use provide
.
; ;
Optional provision
Use get
to consume the context optionally. This returns undefined
if the
context has not been provided.
; ; // name is optional
Use cases
Using call-stack context allows dependencies to be provided deep in the call hierarchy. This idea is inspired from React's conext, which allows dependencies to be provided deep in the component hierarchy. Context allows for more liberal use of dependency inversion, because it reduces the amount of pumbling required to send the dependencies to the use site.
The alternative, i.e. passing dependencies down the call hierarchy, has better traceability.