久久久久久久av_日韩在线中文_看一级毛片视频_日本精品二区_成人深夜福利视频_武道仙尊动漫在线观看

事件驅動架構的jQuery插件?

jQuery plugin for Event Driven Architecture?(事件驅動架構的jQuery插件?)
本文介紹了事件驅動架構的jQuery插件?的處理方法,對大家解決問題具有一定的參考價值,需要的朋友們下面隨著小編來一起學習吧!

問題描述

是否有任何事件驅動架構 jQuery 插件?

Are there any Event Driven Architecture jQuery plugins?


訂閱者訂閱中間的事件處理函數,并傳入一個回調方法,以及他們正在監聽的事件的名稱......


The subscribers subscribe to the event handler in the middle, and pass in a callback method, as well as the name of the event they are listening for...

即兩個綠色訂閱者將監聽 p0 事件.藍色的訂閱者將監聽 p1 事件.

i.e. The two green subscribers will be listening for p0 events. And the blue subscriber will be listening for p1 events.

  1. 一個 p0 事件被觸發到事件處理程序
  2. 事件處理程序通知它的訂閱者該事件,調用他們在訂閱時指定的回調方法步驟 1:訂閱.

請注意,藍色訂閱者不會收到通知,因為它沒有偵聽 p0 事件.

Note that the blue subscriber is not notified because it was not listening for p0 events.

p1 事件被另一個組件觸發

The p1 event is fired by another component

除了現在藍色訂閱者通過它的回調接收事件,而其他兩個綠色訂閱者沒有接收到事件之外,與之前一樣.

Just as before except that now the blue subscriber receives the event through its callback and the other two green subscribers do not receive the event.

Flickr 上 leeand00 的圖片

我似乎找不到,但我猜他們只是在 Javascript/jquery 中將其稱為其他名稱

I can't seem to find one, but my guess is that they just call it something else in Javascript/jquery

還有這種模式的名稱嗎?因為它不僅僅是一個基本的發布者/訂閱者,所以我認為它必須被稱為其他名稱.

Also is there a name for this pattern? Because it isn't just a basic publisher/subscriber, it has to be called something else I would think.

推薦答案

您可能不需要插件來執行此操作.首先,DOM 本身完全是事件驅動的.您可以使用事件委托來監聽根節點上的所有事件(jQuery live 使用的一種技術).要處理可能與 DOM 無關的自定義事件,您可以使用普通的舊 JavaScript 對象來完成這項工作.我寫了一篇博文,介紹在 MooTools 中使用只需一行代碼.

You probably don't need a plugin to do this. First of all, the DOM itself is entirely event driven. You can use event delegation to listen to all events on the root node (a technique that jQuery live uses). To handle custom events as well that may not be DOM related, you can use a plain old JavaScript object to do the job. I wrote a blog post about creating a central event dispatcher in MooTools with just one line of code.

var EventBus = new Class({Implements: Events});

在 jQuery 中也很容易做到.使用作為所有事件的中央代理的常規 JavaScript 對象.任何客戶端對象都可以發布和訂閱此對象上的事件.請參閱這個相關的問題.

It's just as easy to do in jQuery too. Use a regular JavaScript object that acts as a central broker for all events. Any client object can publish and subscribe to events on this object. See this related question.

var EventManager = {
    subscribe: function(event, fn) {
        $(this).bind(event, fn);
    },
    unsubscribe: function(event, fn) {
        $(this).unbind(event, fn);
    },
    publish: function(event) {
        $(this).trigger(event);
    }
};

// Your code can publish and subscribe to events as:
EventManager.subscribe("tabClicked", function() {
    // do something
});

EventManager.publish("tabClicked");

EventManager.unsubscribe("tabClicked");


或者如果你不關心暴露 jQuery,那么只需使用一個空對象并直接在 jQuery 包裝的對象上調用 bindtrigger.

var EventManager = {};

$(EventManager).bind("tabClicked", function() {
    // do something
});

$(EventManager).trigger("tabClicked");

$(EventManager).unbind("tabClicked");

包裝器只是用來隱藏底層的 jQuery 庫,以便您以后可以在需要時替換實現.

The wrappers are simply there to hide the underlying jQuery library so you can replace the implementation later on, if need be.

這基本上是 Publish/Subscribe 或 觀察者模式,一些很好的例子是 Cocoa 的 NSNotificationCenter 類,EventBus 模式由 Ray Ryan 在 GWT 社區和其他幾個社區推廣.

This is basically the Publish/Subscribe or the Observer pattern, and some good examples would be Cocoa's NSNotificationCenter class, EventBus pattern popularized by Ray Ryan in the GWT community, and several others.

這篇關于事件驅動架構的jQuery插件?的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持html5模板網!

【網站聲明】本站部分內容來源于互聯網,旨在幫助大家更快的解決問題,如果有圖片或者內容侵犯了您的權益,請聯系我們刪除處理,感謝您的支持!

相關文檔推薦

jQuery/JavaScript Library for avatar creation?(用于創建頭像的 jQuery/JavaScript 庫?)
How to do following mask input problem?(如何做以下掩碼輸入問題?)
Issues Setting Value/Label Using DropKick Javascript(使用 DropKick Javascript 設置值/標簽的問題)
how to unit-test private methods in jquery plugins?(如何對 jquery 插件中的私有方法進行單元測試?)
stellar.js - configuring offsets / aligning elements for a vertical scrolling website?(stellar.js - 為垂直滾動網站配置偏移量/對齊元素?)
jQuery masked input plugin. select all content when textbox receives focus(jQuery 屏蔽輸入插件.當文本框獲得焦點時選擇所有內容)
主站蜘蛛池模板: 国产极品粉嫩美女呻吟在线看人 | 成人免费看片又大又黄 | 亚洲欧美一区在线 | 久久精品色欧美aⅴ一区二区 | 澳门永久av免费网站 | 国产精品久久久久久亚洲调教 | 黑人精品| 亚洲高清在线观看 | 亚洲成人网在线 | 一级黄色影片在线观看 | 午夜手机在线视频 | 天天干天天爱天天爽 | 精品在线观看一区二区 | 国产精品无码专区在线观看 | 久久久久久久久毛片 | 精品国产99 | 成人国产在线观看 | 精品国产一二三区 | 亚洲国产欧美一区二区三区久久 | av一级久久| 亚洲精品乱码久久久久久9色 | 国产日韩欧美一区 | 自拍偷拍3p | 一级黄色生活视频 | 欧美精品一区在线 | 精品亚洲永久免费精品 | 欧美在线视频二区 | 国产精品美女www爽爽爽 | 99免费在线观看视频 | 在线成人一区 | 在线看91 | 国产精品福利在线 | 这里有精品| 亚洲欧美精| 在线观看免费观看在线91 | 91免费入口 | 欧美一区二区三区在线观看视频 | 久久精品国产一区二区三区不卡 | 中文字幕亚洲视频 | 精品国产乱码久久久久久图片 | 五月婷婷丁香 |