eventproxy 介绍
这个世界上不存在所谓回调函数深度嵌套的问题。 —— Jackson Tian
世界上本没有嵌套回调,写得人多了,也便有了}}}}}}}}}}}}。 —— fengmk2
EventProxy 仅仅是一个很轻量的工具,但是能够带来一种事件式编程的思维变化。有几个特点:
利用事件机制解耦复杂业务逻辑
移除被广为诟病的深度callback嵌套问题
将串行等待变成并行等待,提升多异步协作场景下的执行效率
友好的Error handling
无平台依赖,适合前后端,能用于浏览器和Node.js
兼容CMD,AMD以及Commonjs模块环境
现在的,无深度嵌套的,并行的
var ep = EventProxy.create("template","data","l10n",function (template,data,l10n) {
_.template(template,l10n);
});
$.get("template",function (template) {
// something
ep.emit("template",template);
});
$.get("data",function (data) {
// something
ep.emit("data",data);
});
$.get("l10n",function (l10n) {
// something
ep.emit("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,l10n);
});
});
});
安装
Node用户
通过npm安装即可使用:npm install eventproxy调用:var EventProxy = require('eventproxy');spm
spm install eventproxy
Component
component install JacksonTian/eventproxy
网站地址:http://html5ify.com/eventproxy
GitHub:https://github.com/JacksonTian/eventproxy
网站描述:基于任务/事件的异步模式实现
eventproxy
官方网站:http://html5ify.com/eventproxy
小编说
以上是编程之家为你收集整理的eventproxy全部内容。
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。