callback.km 1.0 KB

123456789101112131415161718192021222324252627282930313233
  1. type EventPayloadConsumer
  2. protected
  3. &(EventPayload) => Async;
  4. function EventHandler:
  5. &(EventPayloadConsumer) => EventHandler
  6. &(cb) => (
  7. { EventHandler ({Callback::[Async] (& e => e)}, cb) }
  8. // important: payload will be deleted after `cb` called
  9. );
  10. export function extract-string:
  11. &(String, &(String) => EventPayloadConsumer) => EventPayloadConsumer
  12. &(prop,k) => { getter-callback (prop, get-string, k) };
  13. export function extract-float:
  14. &(String, &(NormalFloat) => EventPayloadConsumer) => EventPayloadConsumer
  15. &(prop,k) => { getter-callback (prop, get-float, k) };
  16. export function extract-integer:
  17. &(String, &(Integer) => EventPayloadConsumer) => EventPayloadConsumer
  18. &(prop,k) => { getter-callback (prop, get-integer, k) };
  19. export function extract-bool:
  20. &(String, &(Bool) => EventPayloadConsumer) => EventPayloadConsumer
  21. &(prop,k) => { getter-callback (prop, get-bool, k) };
  22. export function trigger:
  23. &(Async) => EventPayloadConsumer
  24. &(action) => { |EventPayloadConsumer| &(_) => action };