Skip to content

Instantly share code, notes, and snippets.

@wmakeev
Last active June 11, 2016 07:40
Show Gist options
  • Save wmakeev/8e397d06aae60644019bdc86e50b9355 to your computer and use it in GitHub Desktop.
Save wmakeev/8e397d06aae60644019bdc86e50b9355 to your computer and use it in GitHub Desktop.
Distributed module declaration
// 1. Module declaration
{
name: 'myModule',
version: '2.1.0',
description: 'Example module',
connectors: {
'customer': {
'createInvoice': {
$meta: {
type: 'handler', // handler | multicast | unicast
flow: 'promise' // sync | promise | csp | callback | generator | fiber
}
}
},
'validateInvoice': {
$meta: {
type: 'unicast',
flow: 'promise'
}
},
'events/newInvioice': {
$meta: {
type: 'multicast',
flow: 'promise'
}
}
},
fn: ({ customer, validateInvoice, events }) => {
return {
init (options) {
customer.createInvoice.on(async customerOrderId => {
// Create invoice
let invoice = { name: 'invoice-001', companyName: options.companyName }
// Validate it
await validateInvoice(invoice)
// Emit event
events.newInvoice(invoice)
/* or theoretically, depending on framework implementation,
we can wait until all events will have been consumed
await events.newInvoice(invoice) */
return invoice
})
}
}
}
}
// 3. Фреймворк генерирует внутреннее сообщение
// https://github.com/acdlite/flux-standard-action
{
type: '[email protected]/createInvoice',
meta: {
type: 'P2P',
channel: 'createInvoice'
},
payload: {
customerOrderId
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment