event.js 627 B

12345678910111213141516171819202122232425262728293031323334
  1. import tauri from './tauri'
  2. /**
  3. * The event handler callback
  4. * @callback eventCallback
  5. * @param {object} event
  6. * @param {string} event.type
  7. * @param {any} [event.payload]
  8. */
  9. /**
  10. * listen to an event from the backend
  11. *
  12. * @param {string} event the event name
  13. * @param {eventCallback} handler the event handler callback
  14. */
  15. function listen (event, handler) {
  16. tauri.listen(event, handler)
  17. }
  18. /**
  19. * emits an event to the backend
  20. *
  21. * @param {string} event the event name
  22. * @param {string} [payload] the event payload
  23. */
  24. function emit (event, payload) {
  25. tauri.emit(event, payload)
  26. }
  27. export {
  28. listen,
  29. emit
  30. }