Advertisement
Guest User

Untitled

a guest
Sep 10th, 2017
154
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.22 KB | None | 0 0
  1. class Foo
  2. {
  3. //Registra os eventos 'baz'
  4. private array baz[];
  5.  
  6. //Registra os eventos 'bar'
  7. private array bar[];
  8.  
  9. //Variavel de exemplo
  10. private int status;
  11.  
  12. public Foo()
  13. {
  14. }
  15.  
  16. public on(string name, Function func)
  17. {
  18. switch (name) {
  19. case 'baz':
  20. baz.push(func);
  21. break;
  22. case 'bar':
  23. baz.push(func);
  24. break;
  25. default:
  26. throw new InvalidEventException;
  27. }
  28. }
  29.  
  30. public changeFoobar(int value)
  31. {
  32. //Se o valor for igual ao anterior não dispara os eventos
  33. if (status != value) {
  34. status = value;
  35. trigger('bar');//Dispara 'bar' quando altera o 'status'
  36. }
  37. }
  38.  
  39. /*dispara os eventos de um tipo especifico*/
  40. protected trigger(string name)
  41. {
  42. array evts[];
  43.  
  44. switch (name) {
  45. case 'baz':
  46. evts = baz;
  47. break;
  48. case 'bar':
  49. evts = bar;
  50. break;
  51. default:
  52. }
  53.  
  54. for (int i = 0; i < evts.length; i++) {
  55. evts[i].call(); //Chama a função
  56. }
  57. }
  58. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement