In need of creating a package that offers abstractions relying on the IObservable
interface, I require two external classes mimicking the behavior of Subject<T>
and BehaviorSubject<T>
from rxjs
.
However, it is essential for me to avoid tightly coupling my package with rxjs
. I aim to make it compatible with other packages implementing these interfaces as well.
I have devised this particular solution. While it serves my needs, I am curious about whether I can rely on the behavior of the import
statement.
This stems from my understanding that import
s are hoisted and executed asynchronously. What if, in some scenarios, myLibrary
is imported before rxjs
and global setup?
EDIT:
My decision was to utilize an init({Subject, ...other_types})
function, which I have incorporated into the updated gist in the provided link. The workflow now follows this pattern:
import {some_types} from 'some_package'
import {init} from 'myLib'
init(some_types)
// ... allowing the consumer to import additional functionalities from myLib
Although I still ponder over the sequencing of import
s, that is a story for another time...