1.0.5 • Published 7 years ago

sugo-module-scoped v1.0.5

Weekly downloads
8
License
Apache-2.0
Repository
github
Last release
7 years ago

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

1.0.5

7 years ago

1.0.4

7 years ago

1.0.3

7 years ago

1.0.2

7 years ago

1.0.1

7 years ago