Skip to content
This repository has been archived by the owner on Sep 23, 2020. It is now read-only.

Commit

Permalink
provide the submodule plugin option 'mediator' to use a custom mediator
Browse files Browse the repository at this point in the history
  • Loading branch information
flosse committed Dec 23, 2013
1 parent c17adb0 commit 74dd391
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 3 deletions.
7 changes: 4 additions & 3 deletions plugins/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -245,9 +245,10 @@ core.register("parent", function(sandbox){

// register the submodule plugin
core.use(scaleApp.plugins.submodule, {
inherit: true, // use all plugins from the parent's Core
use: [somePlugins], // use some additional plugins
useGlobalMediator: true // emit and receive all events from the parent's Core
inherit: true, // use all plugins from the parent's Core
use: [somePlugins], // use some additional plugins
useGlobalMediator: true, // emit and receive all events from the parent's Core
mediator: myCustomMediator // 'useGlobalMediator' has to be falsy
});

core.start("parent");
Expand Down
21 changes: 21 additions & 0 deletions plugins/spec/scaleApp.submodule.spec.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -123,6 +123,27 @@ describe "submodule plugin", ->
@core.permission.add "parent", "on", "to parent"
@core.start "parent"

it "provides an option to use the custom mediator", (done) ->

mySubModule = (sb) -> init: -> sb.emit "x", "z"

mediator = new @scaleApp.Mediator

mediator.on "x", (y) ->
(expect y).to.eql "z"
done()

myModule = (sb) ->
init: ->
sb.sub.register "sub", mySubModule
sb.sub.start "sub"
core = new @scaleApp.Core
core
.use(@plugin, {mediator: mediator})
.boot()
.register("parent", myModule)
.start "parent"

it "provides an option to use the global mediator", (done) ->

mySubModule = (sb) -> init: -> sb.emit "event", "hello"
Expand Down
3 changes: 3 additions & 0 deletions plugins/src/scaleApp.submodule.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,9 @@ plugin = (core, options={}) ->
if options.useGlobalMediator
core._mediator.installTo subCore._mediator, true

else if options.mediator?
options.mediator?.installTo? subCore._mediator, true

# make sure that plugins do not modify the original
# Sandbox class.
subCore.Sandbox = class SubSandbox extends core.Sandbox
Expand Down

0 comments on commit 74dd391

Please sign in to comment.