Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- interface IScreen {
- setCallback(callback: Function);
- display(data: any);
- }
- class BasicOrderFlow {
- private screen: IScreen;
- private orderDetails = {
- vendorId: null,
- dishes: [],
- address: null,
- paymentType: null,
- };
- showScreen(newScreen: IScreen, callback: Function, data: any) {
- this.screen = newScreen;
- this.screen.setCallback(callback);
- this.screen.display(data);
- }
- /** Callback function passed to the vendor selection screen */
- selectVendorCb(vendorId: string) {
- // Validation
- if (!this.isValidVendorId(vendorId)) {
- console.warn('Invalid vendor ID:', vendorId);
- return;
- }
- // Execution
- this.orderDetails.vendorId = vendorId;
- // Transition
- this.showScreen(
- new SelectDishScreen(),
- dishes => this.selectDishCb(dishes),
- { vendorId },
- );
- }
- /** Callback function passed to the dish selection screen */
- selectDishCb(dishes: string[]) {
- // Etc...
- }
- }
Add Comment
Please, Sign In to add comment