事件式编程 EventProxy

码农软件 · 软件分类 · 服务器端JavaScript · 2019-04-13 19:13:13

软件介绍

EventProxy.js仅仅是一个很轻量的工具,但是能够带来一种事件式编程的思维变化。有几个特点:

  1. 利用事件机制解耦复杂业务逻辑
  2. 移除被广为诟病的深度callback嵌套问题
  3. 将串行等待变成并行等待,提升多异步场景下的执行效率
  4. 无平台依赖,适合前后端,能用于浏览器和NodeJS

现在的,无深度嵌套的,并行的

var proxy = new EventProxy();
var render = function (template, data, l10n){
    _.template(template, data);
};
proxy.assign("template", "data", "l10n", render);
$.get("template", function (template) {
    // something
    proxy.trigger("template", template);
});
$.get("data", function (data) {
    // something
    proxy.trigger("data", data);
});
$.get("l10n", function (l10n) {
    // something
    proxy.trigger("l10n", l10n);
});

过去的,深度嵌套的,串行的。

var render = function (template, data){
    _.template(template, data);
};
$.get("template", function (template) {
    // something
    $.get("data", function (data) {
        // something
        $.get("l10n", function (l10n) {
            // something
            render(template, data);
        });
    });
});

本文地址:https://www.codercto.com/soft/d/3513.html

Struts 2 in Action

Struts 2 in Action

Don Brown、Chad Davis、Scott Stanlick / Manning Publications / 2008.3 / $44.99

The original Struts project revolutionized Java web development and its rapid adoption resulted in the thousands of Struts-based applications deployed worldwide. Keeping pace with new ideas and trends......一起来看看 《Struts 2 in Action》 这本书的介绍吧!

HTML 压缩/解压工具
HTML 压缩/解压工具

在线压缩/解压 HTML 代码

JS 压缩/解压工具
JS 压缩/解压工具

在线压缩/解压 JS 代码

html转js在线工具
html转js在线工具

html转js在线工具