You can use it for example with SimQ.
Unfortunately I don't have any more time to maintain this repository :-(
$ npm install extended-spine
Controller = require 'extended-spine'Controller.init($)
Now only spine controller is extended.
Controller = require 'extended-spine/Controller'class MyController extends Controllerconstructor: (@el) ->supermodule.exports = MyController
As you can see, everything is same like in classic spine, only extended class is different.
This module will automatically look for elements in your page with
data-application attribute. If it will not find it, whole html page will
be used. Every element inside this
data-application element with
data-controller element will be used for controller.
Example is much better for explain.
...<div data-application>...<div data-controller="/path/to/controller/for/this/element">...</div>...</div>...
data-controller attribute is path used in require method.
This means that now you don't have to instantiate controllers on your own. :-)
If you like dependency injection pattern with autowired dependencies (again for example like in angular), you can use this feature also with this module.
Uses dependency-injection module.
DI = require 'dependency-injection'di = new DIController.init($, di)
Controller = require 'extended-spine/Controller'class Chat extends Controllerhttp: nulljquery: nullmodel: nullconstructor: (@el, @http, @jquery, @model) ->module.exports = Chat
Chat module is dependent on three services. First argument will always be the container element and others will be services from DI container.
Check documentation of dependency-injection module to see how to add services into your DI container.
This works only with controllers which were created with data-controller attribute.
If your application uses for example ajax for repainting elements, you can use two methods, showed below for refreshing your controllers.
Controller = require 'extended-spine/Controller'Controller.init($)el = $('#element-which-will-be-repainted')$.get(url, (data) ->Controller.unbind(el)el.html(data)Controller.refresh(el))
refresh manipulates also with element on which it was called. You can of course disable that.
Controller.unbind(el, false)Controller.refresh(el, false)
From jQuery element:
menu = $('#menu').getController()// ormenu = $('[data-controller="/app/controller/Menu"]').getController()
menu = Controller.find('/app/controller/Menu')
If you don't want to instantiate some controller immediately, you can add html attribute
<div data-controller="/path/to/my/controller" data-lazy></div>
Now when you want to create instance of this controller, you have to get it's controller factory and use it.
factory = Controller.find('/path/to/my/controller') // for lazy controllers, factory function is returnedcontroller = factory() // just call it and it will return created controller
You can also set if some of your controllers is only for mobile or only for computers.
<div data-controller="/app/controllers/just/for/mobile" data-mobile><div data-controller="/app/controllers/just/for/computer" data-computer>
$ npm test
1.0.2 - 1.0.3