jQuery plugin for Event Driven Architecture?

前端 未结 7 1157
谎友^
谎友^ 2021-01-30 09:00

Are there any Event Driven Architecture jQuery plugins?

Step 1: Subscribing

\"a

7条回答
  •  悲&欢浪女
    2021-01-30 09:50

    This can easily be accomplished using a dummy jQuery node as a dispatcher:

    var someModule = (function ($) {
    
        var dispatcher = $("
    "); function init () { _doSomething(); } /** @private */ function _doSomething () { dispatcher.triggerHandler("SOME_CUSTOM_EVENT", [{someEventProperty: 1337}]); } return { dispatcher: dispatcher, init: init } }(jQuery)); var someOtherModule = (function ($) { function init () { someModule.dispatcher.bind("SOME_CUSTOM_EVENT", _handleSomeEvent) } /** @private */ function _handleSomeEvent (e, extra) { console.log(extra.someEventProperty) //1337 } return { init: init } }(jQuery)); $(function () { someOtherModule.init(); someModule.init(); })

提交回复
热议问题