@angular-resource/pubsub
TypeScript icon, indicating that this package has built-in type declarations

0.0.3 • Public • Published

@angular-resource/pubsub

Publish-Subscriber wrapper of angular-resource

Wraps any Pub-Sub service to promise-like resource. Your Pub-Sub service should answer any message (except cases with timeout: 0)

Example

@PubSubConfig({
  publish: (message?: Action) => {
    window.sendMessage(JSON.stringify(message)) // Send message to the non-http-server
  },
  subscriber: new Observable((subscriber: Subscriber<Action>) => {
    window.handleMessage = (message: string) => { // Receive message from the non-http-server
      subscriber.next(JSON.parse(message))
    }
  }),
  timeout: 10000 // 10s by default. If no confirmation - timeout error
})
export class PubSubResource extends ReactiveResource {
  requestWithoutConfirmation = Send({ timeout: 0 });
  request = Send();
}

PubSubConfig

  • publish (data?: Action) => void - Send message to Pub-Sub service
  • subscriber Observable - Handle events from Pub-Sub service
  • timeout number (default: 10000) - Max request duration in ms
  • autoConnect boolean (default: true) - Connect to Pub-Sub service when application starts
  • mock any | () => any - Returns the value instead of real request
  • observable boolean (default: false) - Return Observable or Promise

Send

  • Send(config?: PubSubConfig) returns (payload: any) => Promise | Observable - Create send method

See also: angular-resource documentation

Readme

Keywords

none

Package Sidebar

Install

npm i @angular-resource/pubsub

Weekly Downloads

3

Version

0.0.3

License

none

Unpacked Size

34.5 kB

Total Files

10

Last publish

Collaborators

  • tamtakoe