This is the fifth day of my participation in Gwen Challenge

I’m going to share a little need with you today.

Demand background

Applet a page, want to applet in the process of use, there is a cancel button, the function of the button is to exit the applet or jump to another page. When we click the “cancel” button, we need to pop up a modal box, which is used to give the user a confirmation feedback for clicking the button to prevent the user from misoperation. It seems that this requirement is very simple, we can completely call the showModal method of wechat to achieve. It’s easy. But the product hole came out. What he wanted was for the sequence of user actions to be cached during the popover, and then to have the sequence of events during the popover executed when we unpopped it. There is a premise to tell you, because our little program involves webSocket so some events are done by monitoring.

Through the above requirement analysis, we can deal with it well. When we click the button, we can add a variable to save whether our popover is displayed. If a popover is displayed, we can use this variable to handle webSocket listening methods. Store the methods displayed during the popover into the array. When we cancel the popover display, extract the events to be executed from the array, execute.

This is similar to the definition of a queue. Queue: a special linear table that allows data insertion at one end and data deletion at the other end; The end that performs insertion operations is called the end of the queue (entering the queue), and the end that performs deletion operations is called the end of the queue (exiting the queue). Queues have a first-in, first-out (FIFO) feature. Stack: As a data structure, a stack is a special linear table that can only be inserted and deleted at one end. It stores data on a “first in, last out” basis. The first data is pushed to the bottom of the stack, and the last data is pushed to the top of the stack. When data needs to be read, data is ejected from the top (the last data is read first).