sugo-module-scoped
v1.0.5
Published
Scoped module for SUGOS
Downloads
1
Readme
sugo-module-scoped
Scoped module for SUGOS
Installation
$ npm install sugo-module-scoped --save
Usage
Define Module
'use strict'
const { scoped } = require('sugo-module-scoped')
const sugoHub = require('sugo-hub')
const sugoActor = require('sugo-actor')
// Define module with dynamic scope variables
const fruitShop = scoped((session) => ({
buy (product, amount) {
let ordererId = session.who
/* ... */
}
}))
let hub = sugoHub({
localActors: {
shoppingMall: sugoActor({
modules: {
fruitShop
}
})
}
})
hub.listen(3000)
Call from caller
'use strict'
const sugoCaller = require('sugo-caller')
const sugoScope = require('sugo-scope')
const co = require('co')
let caller = sugoCaller({ /* ... */ })
let session = sugoScope()
co(function * () {
let shoppingMall = yield caller.connect('shoppingMall')
// Login and store into session scope
session.who = yield shoppingMall.get('auth').signin('user01', 'xxx-password-01')
// Access to module with a scope
let fruitShop = shoppingMall.get('fruitShop').with(session)
yield fruitShop.buy('Orange', 3)
}).catch((err) => console.error(err))
License
This software is released under the Apache-2.0 License.