The Publish-subscribe mode in JS Event

Source: Internet
Author: User

I. How do you understand the publish subscription model?
    • JS in the design mode:
      • Singleton mode: Handling business logic
      • Construct prototype mode: Encapsulate Class Library, component, frame, plugin, etc.
        • Class Library: JQuery
          • Just provides a few common methods that can be applied to any project, not business
        • Component: Bootstrap
          • A lot of common components are provided (Html/css/js are prescribed by others), we only need to use as required, we can directly achieve the effect
        • Plugin: Swiper/iscroll
          • Package for a specific business, such as a tab plug-in or a Carousel diagram plugin
        • Frame: React/vue
          • A certain programming idea (MVC/MVVM) is called a frame
      • Publish subscription Model: to handle some specific requirements
      • Promise mode: Dealing with some specific needs
    • Publish subscription Mode
      • Publish a schedule (publish)
      • Add something to your schedule (subscribe)
Two. Publish subscription mode

Publish subscription mode is not a dead mechanism, he is a kind of thought, a form of writing code, mainly in order to deal with a one-to-many scenarios, applied to different functions of the call, this is very important

    • Manually simulate the browser event mechanism

      1. Subscription

      1. Release
        • Perform
    • Change this point

      1. Create a small tool box
      2. Put our methods in the Little tool box.
      3. When we want to use this method, we can go directly to the Small tool box variable.
    • The problem of dealing with order, in fact, is to deal with the problem of IE event pool chaos, then we can not use the event pool of IE, we simulate an event pool (using the idea of publishing subscriptions to simulate our event pool)

      1. Add handlers when listening
      2. The handlers for the events that are being monitored are executed at the time of release

The Publish-subscribe mode in JS Event

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.