daily pastebin goal
51%
SHARE
TWEET

Untitled

a guest Dec 18th, 2018 51 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. interface IScreen {
  2.   setCallback(callback: Function);
  3.   display(data: any);
  4. }
  5.  
  6. class BasicOrderFlow {
  7.   private screen: IScreen;
  8.  
  9.   private orderDetails = {
  10.     vendorId: null,
  11.     dishes: [],
  12.     address: null,
  13.     paymentType: null,
  14.   };
  15.  
  16.   showScreen(newScreen: IScreen, callback: Function, data: any) {
  17.     this.screen = newScreen;
  18.     this.screen.setCallback(callback);
  19.     this.screen.display(data);
  20.   }
  21.  
  22.   /** Callback function passed to the vendor selection screen */
  23.   selectVendorCb(vendorId: string) {
  24.     // Validation
  25.     if (!this.isValidVendorId(vendorId)) {
  26.       console.warn('Invalid vendor ID:', vendorId);
  27.       return;
  28.     }
  29.    
  30.     // Execution
  31.     this.orderDetails.vendorId = vendorId;
  32.    
  33.     // Transition
  34.     this.showScreen(
  35.       new SelectDishScreen(),
  36.       dishes => this.selectDishCb(dishes),
  37.       { vendorId },
  38.     );
  39.   }
  40.  
  41.   /** Callback function passed to the dish selection screen */
  42.   selectDishCb(dishes: string[]) {
  43.     // Etc...
  44.   }
  45. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top