mirror of
https://github.com/frappe/books.git
synced 2024-12-26 20:30:25 +00:00
773 B
773 B
Observable Base Class
The Observable
base class makes and subclass trigger events and accept event listeners.
Example
class Test extends Observable {
doSomething() {
// work
this.trigger('work-done', {some: params})
}
}
let test = new Test();
test.on('work-done', (params) => yay());
With Sockets
You can also bind sockets (SocketIO) to an Observable
and all events will also be emitted or received via the socket. See the API below for binding sockets.
Methods
on(event, listener)
: Listen to an eventtrigger(event)
: trigger an eventonce(event, listener)
: trigger an event oncebindSocketServer(socket)
: Emit triggers on this socketbindSocketClient(socket)
: Listen for events on this socket