Advertisement
Guest User

Untitled

a guest
Jun 25th, 2019
86
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. option 2: component-specific object
  2. GridLayout Interaction State
  3. {
  4.     selectedChildId: ViewerId,
  5.     isHighlighted: boolean,
  6. }
  7.  
  8. interactionManager.getAllComponents().withType('GridLayout').subscribe(
  9.     'onEnterPressed',
  10.     (subscriber: { ..., interactionState: GridLayout Interaction State }, message, globalState) => {
  11.         if (globalState.selected === subscriber.viewerId) {
  12.             console.log('I'm the selected one!');
  13.            interactionManager.publish({
  14.                eventName: 'PrintSomething',
  15.                message: {  },
  16.            });
  17.        }
  18.        globalState.selected = subscriber.viewerId;
  19.    }
  20. );
  21.  
  22. type ViewerHandle = {
  23.    viewerId: ViewerId,
  24.    parent: ViewerHandle,
  25. };
  26.  
  27. type GridLayoutHandle extends ViewerHandle = {
  28.     viewModel: {
  29.         type: 'GridLayout',
  30.         content: null,
  31.         metadata: null,
  32.    },
  33.     selectedChildId: ViewerId,
  34. }
  35.  
  36. type InteractionState = {
  37.    
  38. };
  39.  
  40. type InteractionManager = {
  41.    
  42. };
  43.  
  44. im.type().filter()
  45.  
  46. im.forEach()
  47.  
  48. im.type('GridLayout').forEach((viewer: ViewerHandle<GridLayout>) => {
  49.    viewer.on('onEnterPressed', (message: Message, global: InteractionState) => {
  50.        if (global.selectedId === viewer.viewerId) {
  51.            im.emit('PrintSomething', {});  // (topic, message)
  52.        }
  53.        console.log(viewer.selectedChildId);
  54.    });
  55.    viewer.on('onEscPressed', (message, globalState) => {
  56.    
  57.    });
  58. });
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement