How do I access config data inside models

Do models have access to config options specified in application.json

Especially when I run Test cases.

4 Replies
  • No, models are shareable piece of code, and normally having those pieces pulling data from a particular app-specific structure is bad. Instead, we recommend pushing data/config into the models.

    In other words, you can do something like:

    var foo = ac.models.get('foo'); foo.doSomething(someData, callback);

    where "someData" is something that you can put together in your dispatcher.

    That being said, if the model has a "init" method, a config structure, with the mojit's configuration will be passed into it at the moment you access it thru ac.models.get``, and this configuration is a combination of defaults.json (from the mojit itself) and the config fromspecs` in application.json for the mojit's instance.

    So, you do have few ways to pass data around :)

  • Yup I got that. It works fine for the app but my question was how I can use that in a TestSuite where actioncontext object is not available.

  • As I mentioned in another reply for one of your questions, you have to mock it :)

    I will recommend you to look at some of the tests under yahoo/mojito/tests/units/, to see how to mock "ac". Any data used, or required, by any YUI module that you have in your application, you should mock it when it comes to tests.

  • Yup! Got it.


Recent Posts

in Yahoo! Mojito