A small package to use reactive dependency injection in Meteor.
If something is really good in Meteor, that is reactivity.
With a reactive dependency system:
Just run this in your project folder:
meteor add meteorflux:reactive-dependency
It's quite similar to Tracker.autorun
. Inside your object or class you declare your dependencies like this:
// Dependency Injection
var _otherObject, _anotherObject;
Dependency.autorun(function(){
_otherObject = Dependency.get('OtherObject');
_anotherObject = Dependency.get('AnotherObject');
});
And after the creation of each object/class, you add it to the system like this:
// Create instance and add it
var otherObject = new OtherObject();
Dependency.add('OtherObject', otherObject);
Reactivity takes cares of the rest.
Remember that you don't have to access any object before Meteor.startup()
because you don't know if Meteor has already loaded that file or not.
This is not bad, it's how Meteor normally works and the reason Meteor.startup()
exists.
I have created this package to use in conjunction with my MeteorFlux Dispatcher.
In the Flux architecture, your logic is kept inside Stores. Those Stores need to communicate between each other so a good dependency system is needed.
MeteorFlux is still a work in progress. You can follow it in this forum post:
https://forums.meteor.com/t/meteorflux-flow/920/
You don't need to use Flux or the Dispatcher to use this package. Actually, I hope it can be useful in many other cases, so I've released this first.
I have created an example in this Github repo:
https://github.com/meteorflux/reactive-dependency-example
Feel free to express your feelings in this forum post or here in the Github Issues.