Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Are there any inversion of control frameworks for javascript?

Are there any inversion of control frameworks for javascript?

The closest answer available on stackoverflow that I could find is here: What is the right way to wire together 2 javascript objects? . It looks like a great start, but I thought I'd be able to find something with a longer development history.

I've only used Castle Windsor myself, and I am really missing it in web-client land.

like image 342
Frank Schwieterman Avatar asked Sep 15 '09 04:09

Frank Schwieterman


2 Answers

I started writing one that I never got around to finishing. Not sure if I ever will as the overhead probably isn't worth it. if you're interested, it's at: http://code.google.com/p/jasproject/wiki/JasFac (that's the IoC portion, the full suite is at http://code.google.com/p/jasproject/)

The mocking library is fairly complete (no expectations though, at the moment i just use assertions on the mocks/stubs) but the unit testing framework is lacking. The IoC portion is pretty complete but might have a few bugs (don't think so though)

Feel free to use it and/or contribute, I can help where you need.

EDIT: More usage can be seen in the unit tests for jasfac: https://jasproject.googlecode.com/svn/trunk/Jas.Tests/JasFacTests.js

like image 181
Luke Schafer Avatar answered Oct 24 '22 14:10

Luke Schafer


I was looking for one last year and ran across squirrel-ioc. There was something I didn't like about it - I think it only supported singleton style instances.

Squirrel is an IoC container implemented in Javascript to promote the better use of architecture and patterns in browser-based Javascript applications

I started writing my own and got pretty far (constructor and setter injection, values and reference relationships, singleton support, JsUnit tests) but never really needed it in my application. I may have to check out Luke's project. For reference, here is an example of the configuration format I ended up with.

var iocConfig = {
  "a" : { Type : A },
  "b1" : { Type : B, Props : [{Name : 'Letter', Ref : "a"}]  },
  "b2" : { Type : B, Props : [{Name : 'Letter', Val : "a"}]  },
  "c2" : { Type : C, Args : [{Ref : "a"}, {Val : "a"}]  },
  "d" : { Type : D, Props : [{Name : 'Letter', Ref : "a"}]  },
  "date" : { Type : Date, Props : [{Name : 'FullYear', Val : 2008}, {Name : 'Month', Val : 0}, {Name : 'Date', Val : 1}]  },
  "array3" : { Type : Array, Args : [{Val : 3}]  },
  "number1" : { Type : Number, Args : [{Val : 1}]  },
  "string1" : { Type : String, Args : [{Val : "1"}]  },
  "s-true" : { Type : S, Singleton : true},
  "s-false" : { Type : S, Singleton : false}
};
like image 21
Kevin Hakanson Avatar answered Oct 24 '22 12:10

Kevin Hakanson