tevents.nim 1.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849
  1. discard """
  2. output: '''
  3. HandlePrintEvent: Output -> Handled print event
  4. HandlePrintEvent2: Output -> printing for ME
  5. HandlePrintEvent2: Output -> printing for ME
  6. '''
  7. """
  8. import events
  9. type
  10. PrintEventArgs = object of EventArgs
  11. user*: string
  12. proc handleprintevent*(e: EventArgs) =
  13. write(stdout, "HandlePrintEvent: Output -> Handled print event\n")
  14. proc handleprintevent2*(e: EventArgs) =
  15. var args: PrintEventArgs = PrintEventArgs(e)
  16. write(stdout, "HandlePrintEvent2: Output -> printing for " & args.user)
  17. var ee = initEventEmitter()
  18. var eventargs: PrintEventArgs
  19. eventargs.user = "ME\n"
  20. ##method one test
  21. ee.on("print", handleprintevent)
  22. ee.on("print", handleprintevent2)
  23. ee.emit("print", eventargs)
  24. ##method two test
  25. type
  26. SomeObject = object of RootObj
  27. printEvent: EventHandler
  28. var obj: SomeObject
  29. obj.printEvent = initEventHandler("print")
  30. obj.printEvent.addHandler(handleprintevent2)
  31. ee.emit(obj.printEvent, eventargs)
  32. obj.printEvent.removeHandler(handleprintevent2)
  33. ee.emit(obj.printEvent, eventargs)