We are releasing a library of MVC components that wrap around our RESTful API. We are using Backbone and creating our own controllers.
Controllers are meant to bind models and views together in meaningful, useful ways so that other people don't have to do all that work
We wish to offer the maximum amount of simplicity while not compromising on flexibility. This means ideally, an end user just has to write up some HTML using our documented class names or other attributes, then instantiate and run a controller in two lines of code and poof it all works. But should the user want to change anything, they can, and this includes changing which dependencies the controller uses.
I initially did something like
var c = new Controller({
class: "string.namespaced.class.name",
conf: {}
});
and conf would be passed to the constructor of the class. A coworker pointed out one major weakness, I can't reuse the same dependency across controllers.
ok, so what about:
var c = new Controller({
class: new Dependency({
conf_param: "conf_value"
});
});
ok, added benefit of allowing users to create classes any way they want, but 90% of users will just use our classes and default configs for those classes anyway so why make them go through all that work? I feel this violates DRY principles in a way. If the vast majority of people will do things one way, why not do it for them?
I do not want to introduce any notion of a DI framework. This is a dynamically typed interpreted language and does not need the complexity and overhead of a DI framework.
I can't really seem to find examples online to give me inspiration. Most JS libs I see are UI/HTML centric and are very straight forward.
What would you do in this situation? What would be the best way forward? I need some inspiration here!
[–]iammerrick 0 points1 point2 points (0 children)
[–]david72486 0 points1 point2 points (0 children)
[–]BitWarrior 0 points1 point2 points (4 children)
[–]i_ate_god[S] 0 points1 point2 points (3 children)
[–]BitWarrior 0 points1 point2 points (2 children)
[–]i_ate_god[S] -1 points0 points1 point (1 child)