@angular-resource/pubsub
v0.0.3
Published
Publish-Subscriber wrapper of angular-resource
Downloads
24
Readme
@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 servicesubscriber
Observable - Handle events from Pub-Sub servicetimeout
number (default: 10000) - Max request duration in msautoConnect
boolean (default: true) - Connect to Pub-Sub service when application startsmock
any | () => any - Returns the value instead of real requestobservable
boolean (default: false) - Return Observable or Promise
Send
Send(config?: PubSubConfig)
returns (payload: any) => Promise | Observable - Create send method
See also: angular-resource documentation