Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // interface any visitor should extend
- // define visit* function for all types
- class Visitor {
- visitChannel(entity) {}
- visitApp(entity) {}
- visitGroup(entity) {}
- visitProgram(entity) {}
- }
- // specific implementation of visitor
- // it encapsulates details of operation inside of a method
- class EnterKeyVisitor extends Visitor {
- visitChannel(entity) {
- // conversion to domain entity may happen here e.g. new Channel(...)
- // or the domain entity may be taken from entity directly if it is "pre-cooked" there e.g. entity.actionData
- const actionPaylod = null;
- WatchFlow.watchChannel(actionPaylod);
- }
- vistApp(entity) {
- const actionPaylod = null; // same as above
- AppsActions.openApp(actionPaylod);
- }
- visitGroup(entity) {
- const actionPaylod = null; // same as above
- DPActions.openDetailPage(actionPaylod);
- }
- visitProgram(entity) {
- const actionPaylod = null; // same as above
- DPActions.openDetailPage(actionPaylod);
- }
- }
- class BaseSearchEntity {
- get primaryMetadata() {
- return '';
- }
- get secondaryMetadata() {
- return '';
- }
- visit(visitor) {
- return null;
- }
- }
- class ChannelViewEntity extends BaseSearchEntity {
- get primaryMetadata() {
- return this._data.chanelName;
- }
- get secondarMetadata() {
- return 'channel metadata';
- }
- visit(visitor) {
- return visitor.visitChannel(this);
- }
- }
- class SearchView extends BaseView {
- onKey(key) {
- const activeElement = this._list.getSelectedItemData();
- switch (key) {
- case Keys.Enter:
- return activeElement.visit(enterKeyVisitorInstance)
- case Keys.Play:
- return activeElement.visit(playKeyVisistorInstance);
- case Keys.Contextual:
- return activeElement.visit(contextualKeyVisitorInstance);
- }
- }
- }
Add Comment
Please, Sign In to add comment