This is a library to add "Service Objects" to Marionette 2.1.x. Service Objects are an extension of Marionette.Object that
allows declarative interaction with Backbone.Radio messages. Service Objects can respond to any of Radio's three message types; Events
, Commands
and Requests
. The syntax is similar to the events
syntax from Backbone Views, and looks like this:
radioEvents: {
'app start': 'onAppStart',
'books finish': 'onBooksFinish',
},
radioCommands: {
'app doFoo': 'executeFoo',
},
radioRequests: {
'resources bar': 'getBar',
},
where each hash value is in the form 'channel eventName' : 'handler'
. So
radioCommands: {
'app doFoo': 'executeFoo',
},
means that the Service will listen for the doFoo
command on the app
channel, and run the 'executeFoo' method. When using Radio Commands and Requests with Objects, the same rules and restrictions that normal Radio use implies also apply here: a single handler can be associated with a command or request, either through manual use of the comply or reply functions, or through the Service API.
npm install marionette-service
bower install marionette-service
There is a PR to include this feature in Marionette v3.0.0. This library is intended as a way to use the feature in 2.1+ apps without having to wait for 3.0.
Marionette 3.0 isn't finalized yet. APIs may change in the meantime. I don't want updating to 3.0 to break any existing service code. If the API does change I will try to track it with this library, but will do so in a semver fashion. Assuming that the API does remain stable, upgrading to the core code will consist of renaming all Service
objects to Object
and removing this dependency.