sugo-module-scoped

1.0.5 • Public • Published

sugo-module-scoped

Build Status npm Version JS Standard

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.

Links

Readme

Keywords

Package Sidebar

Install

npm i sugo-module-scoped

Weekly Downloads

5

Version

1.0.5

License

Apache-2.0

Last publish

Collaborators

  • realglobe