0.0.1 • Published 6 years ago

moleculer-nativecall v0.0.1

Weekly downloads
3
License
MIT
Repository
github
Last release
6 years ago

Moleculer NativeCall

Use other services as native objects for MoleculerJS framework

Install

$ npm install nervmouse/moleculer-nativecall

Usage

The ordinary way to call an action of service math

//Ordinay way to call `math.add`
ctx.call('math.add',{a:5,b:3}).then(res=> console.log('5+3=',res));

//Use NativeCall to call `math.add`
math.add({a:5,b:3}).then(res=> console.log('5+3=',res));

Sample Service

const NativeCall=require('moleculer-nativecall');
module.exports = {
	name: "sample",
	// Actions
	actions: {
		test (ctx){
			return math.add({a:5,b:3}).then(res=> `5+3=${res}`)
		}
	},
	// use NativeCall.require function in event handler
	started() {
        return NativeCall.require(this.broker,['math'],global);
	}
};

API

NativeCall object

require()

require(broker: ServiceBroker, services: Array [, env: object])

Parameters
PropertyTypeDefaultDescription
brokerServiceBroker-broker for accessing services
servicesArray-List of services to be loaded
envObject{}(optional) The place to assign service objects. The object will be return in promise. eg. global
Return

a promise will be return with env

NativeCall.require(broker,['math']).then($env=>{
  //$env.math will be the service object 
});

License

MIT license