Guest User

Untitled

a guest
Dec 13th, 2018
87
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.82 KB | None | 0 0
  1. // interface any visitor should extend
  2. // define visit* function for all types
  3. class Visitor {
  4. visitChannel(entity) {}
  5.  
  6. visitApp(entity) {}
  7.  
  8. visitGroup(entity) {}
  9.  
  10. visitProgram(entity) {}
  11. }
  12.  
  13. // specific implementation of visitor
  14. // it encapsulates details of operation inside of a method
  15. class EnterKeyVisitor extends Visitor {
  16. visitChannel(entity) {
  17. // conversion to domain entity may happen here e.g. new Channel(...)
  18. // or the domain entity may be taken from entity directly if it is "pre-cooked" there e.g. entity.actionData
  19. const actionPaylod = null;
  20. WatchFlow.watchChannel(actionPaylod);
  21. }
  22.  
  23. vistApp(entity) {
  24. const actionPaylod = null; // same as above
  25. AppsActions.openApp(actionPaylod);
  26. }
  27.  
  28. visitGroup(entity) {
  29. const actionPaylod = null; // same as above
  30. DPActions.openDetailPage(actionPaylod);
  31. }
  32.  
  33. visitProgram(entity) {
  34. const actionPaylod = null; // same as above
  35. DPActions.openDetailPage(actionPaylod);
  36. }
  37. }
  38.  
  39. class BaseSearchEntity {
  40.  
  41. get primaryMetadata() {
  42. return '';
  43. }
  44.  
  45. get secondaryMetadata() {
  46. return '';
  47. }
  48.  
  49. visit(visitor) {
  50. return null;
  51. }
  52.  
  53. }
  54.  
  55. class ChannelViewEntity extends BaseSearchEntity {
  56. get primaryMetadata() {
  57. return this._data.chanelName;
  58. }
  59.  
  60. get secondarMetadata() {
  61. return 'channel metadata';
  62. }
  63.  
  64. visit(visitor) {
  65. return visitor.visitChannel(this);
  66. }
  67. }
  68.  
  69. class SearchView extends BaseView {
  70. onKey(key) {
  71. const activeElement = this._list.getSelectedItemData();
  72.  
  73. switch (key) {
  74.  
  75. case Keys.Enter:
  76. return activeElement.visit(enterKeyVisitorInstance)
  77.  
  78. case Keys.Play:
  79. return activeElement.visit(playKeyVisistorInstance);
  80.  
  81. case Keys.Contextual:
  82. return activeElement.visit(contextualKeyVisitorInstance);
  83. }
  84. }
  85. }
Add Comment
Please, Sign In to add comment