@glue42/ng-glue

Glue42 library for Angular

Usage no npm install needed!

<script type="module">
  import glue42NgGlue from 'https://cdn.skypack.dev/@glue42/ng-glue';
</script>

README

NgGlue42

Installation

npm install @glue42/desktop @glue42/ng-glue

Importing the Glue42 NgModule

Once installed NgGlue42Module needs to be imported and the static method withConfig to be invoked with an optional configuration. withConfig inits an instance of Glue library:

import { NgGlue42Module } from '@glue42/ng-glue';

@NgModule({
  imports: [
    NgGlue42Module.withConfig({})
  ]
})
export class AppModule { }

Using the library

Start using by injecting any of the provided API into your components and services. For example: In one app listen for a certain method to be registered and immediately invoke it when it becomes available:

import { Component, OnInit } from '@angular/core';
import { InteropService } from '@glue42/ng-glue';
import { mergeMap } from 'rxjs/operators';

@Component({
  selector: 'app-root',
  templateUrl: 'app.component.html'
})
export class AppComponent implements OnInit {

  constructor(public interopService: InteropService) { }

  ngOnInit(): void {
    this.interopService.methodRegistered({ methodName: 'Sum' })
      .pipe(
        mergeMap(
          () => this.interopService.invoke('Sum', { a: 37, b: 5 })
        )
      ).subscribe(result => {
        console.log(`The result of 37 + 5 is ${result.returned.answer}`);
      });

  }
}

In another app register the method:

this.interopService.register('Sum', ({ a, b }) => ({ answer: a + b }))
  .subscribe(
    method => console.log(`Method "${method.name}" is registered.`),
    error => console.log(`Couldn't register method "Sum"`, error)
  );