OS.js icon indicating copy to clipboard operation
OS.js copied to clipboard

Enhance Service Provider to Support Chained Parsing Methods

Open maryam4s26 opened this issue 5 months ago • 10 comments

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();

maryam4s26 avatar Sep 15 '24 17:09 maryam4s26