new SenecaPromisified()
Meant to wrap the global seneca instance.
Methods
(static) create()
Just an alternate way to instantiate the class...
(static) use(fn)
Modifies the prototype to add new methods.
Parameters:
Name | Type | Description |
---|---|---|
fn |
function | Side effecting function which changes the prototype. |
act() → {Promise}
Calls a seneca handler.
Returns:
- Type
- Promise
Example
// These all do the same thing...
seneca.act('foo:true,bar:false').then(console.log);
seneca.act({ foo: true, bar: false }).then(console.log);
seneca.act('foo:true', { bar: false }).then(console.log);
add()
Adds a handler to the internal seneca instance.
Example
this.add({ cmd: 'foobar' }, function(args) {
return Promise.resolve('FOOBAR');
});
close() → {Promise}
Closes the connection established by listen
.
Returns:
- Type
- Promise
create(seneca) → {SenecaPromisified}
This is only there to allow classes which inherit from this one to override what the methods return. If you extend this class you should override this method to return a new instance of this one for the internals to work properly.
Parameters:
Name | Type | Description |
---|---|---|
seneca |
Object | Is the callback-base seneca instance. |
Returns:
- Type
- SenecaPromisified
delegate(opts) → {SenecaPromisified}
Returns a new seneca object which will automatically add the given properties to the object you send.
Parameters:
Name | Type | Description |
---|---|---|
opts |
Object | The properties to automatically add. |
Returns:
- Type
- SenecaPromisified
Example
const delegated = seneca.delegate({ safe: false });
// The object submitted will also have the `safe` property.
delegated.act({ cmd: 'ping' });
listen() → {Undefined}
Opens a connection.
Returns:
- Type
- Undefined
pin() → {Object}
Similar to delegate.
Returns:
- Type
- Object
Example
seneca.add({ cmd: 'save', entity: 'person' }, (args) => {
return { saved: true };
});
seneca.add({ cmd: 'load', entity: 'person' }, (args) => {
return { loaded: true };
});
const pin = seneca.pin({ cmd: '*', entity: 'person' });
pin.load({}).then(console.log); // => `{ loaded: true }`
pin.save({}).then(console.log); // => `{ saved: true }`
prior(args)
Automatically patched on the SenecaPromisified instance.
Parameters:
Name | Type | Description |
---|---|---|
args |
Object | Is the args object to pass to the next handler |
Example
seneca.add({ foo: 'bar' }, (args) => {
return { response: 1 };
});
seneca.add({ foo: 'bar' }, (args, seneca) => {
return seneca.prior(args).then(({ response }) => {
return {
response: response + 1
};
});
});
seneca.act({ foo: 'bar' }).then(console.log); // => `{ response: 2 }`
ready() → {Promise}
Returns a promise which will be resolved when seneca is loaded.
Returns:
- Type
- Promise
use() → {Undefined}
Returns:
- Type
- Undefined
Example
seneca.use((seneca) => {
seneca.add({ cmd: 'ping' }, (args, seneca) => {
return seneca.act({ cmd: '' });
});
});
Or:
seneca.use(function() {
this.add({ cmd: 'pong' }, function(args) {
return this.act({ cmd: 'ping' });
});
});