OS.js
OS.js copied to clipboard
Enhance Service Provider to Support Chained Parsing Methods
hello @andersevenrud. I reviewed the section on creating a service provider in the osjs documentation.
// src/client/myprovider.js
export class MyApiServiceProvider
{
constructor(core, options = {}) {
this.core = core;
this.options = options;
}
provides() {
return ['namespace/api'];
}
async init() {
this.core.singleton('namespace/api', () => ({
greet: name => alert(`Hello ${name}!`)
}));
}
}
// src/client/index.js
import {MyApiServiceProvider} from './myprovider.js';
// ...
osjs.register(MyApiServiceProvider);
// ...
This service provider is called as follows:
OSjs.make('namespace/api').greet('World');
But I want to have a service provider that can be called this way:
OSjs.make('namespace/api').greet('World').firstParser();
OSjs.make('namespace/api').greet('World').secoundParser();