4.0.0 • Published 7 months ago

@aloreljs/ngx-sails v4.0.0

Weekly downloads
27
License
MIT
Repository
github
Last release
7 months ago

Greenkeeper badge Build Status Coverage Status

Angular bindings for the sails socket client

Used the abandoned ngx-sails as a base.

Installation

Angular 8:

npm install @aloreljs/ngx-sails@^1.0.0 socket.io-client@^2.0.0

Configuration

The following injection tokens can be included in your app module to configure the client:

Provide an existing socket.io instance:

import {IO_INSTANCE} from '@aloreljs/ngx-sails';

@NgModule({
  providers: [{
    provide: IO_INSTANCE,
    useValue: someIoRef
  }]
})
export class AppModule {}

Provide client configuration:

import {NGX_SAILS_CONFIG, NgxSailsConfig} from '@aloreljs/ngx-sails';

const config: NgxSailsConfig = {
  uri: '/foo',
  // socket.io options
  options: {
  
  },
  // default headers
  headers: {
  
  }
}

@NgModule({
  providers: [{
    provide: NGX_SAILS_CONFIG,
    useValue: config
  }]
})
export class AppModule {}

Usage

import {SailsClient} from '@aloreljs/ngx-sails';

@Component({})
export class MyComponent {
  public constructor(private readonly sails: SailsClient) {}

  public listenForEvent(): void {
    this.sails.on('eventName').subscribe(response => {});
  }
 
  public makeRequest(): void {
    this.sails.get('url').subscribe();
    this.sails.post('url', {foo: 'bar'}).subscribe(response => {});
  }

  public emitEventWithoutAResponse(): void {
    this.sails.emit('eventName', 'arg1', 'arg2');
  }

  public emitEventWithAResponse(): void {
    this.sails.emitAndWait('eventName', 'arg1', 'arg2').subscribe(response => {})
  }
}
4.0.0

7 months ago

3.0.0

1 year ago

2.1.0

2 years ago

2.0.1

2 years ago

2.0.0

2 years ago

1.1.2

5 years ago

1.1.1

5 years ago

1.1.0

5 years ago

1.0.2

5 years ago

1.0.1

5 years ago

1.0.0

5 years ago