-
Notifications
You must be signed in to change notification settings - Fork 55
Module structure
SOCR Framework is designed to be highly scalable. Adding new modules to it's infrastructure is pretty easy. According to Architecture requirements, each module has to have standard structure.
Empty template
First of all, each module is an Angular module
'use strict'
myModule = angular.module('app.myModule', [
])
Config block
Every module have it's own config
block which is started at the stage of module initialization. Services, providers from ng
module (such as $http
, $resource
) can be injected in config
. Note, that services, providers in this module cannot be injected in the config
block, because it's run before their initialization.
.config([
() ->
console.log "config block of myModule module"
])
Event Manager
This is another essential module component. Every module has to have a MODULE_NAMEEventMngr()
service which provides messaging with core
.service('myModuleEventMngr', [
() ->
sb = null
msgList =
outcome: ['outcomeMsg']
income: ['incomeMsg']
scope: ['myModule']
eventManager = (msg, data) ->
# here goes implementation of inner listener
setSb: (_sb) ->
return false if _sb is undefined
sb = _sb
getMsgList: () ->
msgList
listenToIncomeEvents: () ->
console.log 'subscribed for ' + msgList.income[0]
sb.subscribe
msg: msgList.income[0]
listener: eventManager
msgScope: msgList.scope
sum: sum
])
Factory
Module initialization is handled by the Core module of the Framework by invoking the Angular factory of the same name. For example, app.myModule
module has to have myModule
factory. Factory takes Sandbox object sb
as a parameter. Factory returns an object containing methods init()
and destroy()
and message list msgList
. In the init()
method module subscribes for messages from it's own components (communication within the module).
.factory('myModule', [
# Factory has Event Manager as a dependency
'myModuleEventMngr'
(myModuleEventMngr) ->
# Sandbox is used in Event Manager for communications
(sb) ->
# List of messages is retrieved from Event Manager
msgList = myModuleEventMngr.getMsgList()
myModuleEventMngr.setSb sb unless !sb?
# This method invoked on module initialization
init: (opt) ->
console.log 'myModule init invoked'
myModuleEventMngr.listenToIncomeEvents()
# This method invoked on module destruction
destroy: () ->
# Return list of messages to Core
msgList: msgList
])