轻量级JavaScript逻辑框架 – tas

weixin_38053367 2019-09-12 12:58:31
Tas.js Tas是一个轻量级JavaScript逻辑框架,无依赖。 便于使用 学习零成本。使用JavaScript的基础语法,你可以写出绝大多数的任务。 无需以回调的给事编写任务,只需按照逻辑顺序 通过返回或这个将数据传递给下一个函数或任务 安装 Node.js: $ npm install tas --save Web / RequireJS: 下载Tas.js 或 Tas.min.js . 入门示例 同步任务 tas("My first tasks", { t1: function () { return [1, 2, 3]; }, t2: function(a, b, c){ console.log(a, b, c); // 1 2 3 return [4, 5, 6]; } }); tas("My Second tasks", { t3: { t4: function (a, b, c) { console.log(a, b, c); // 4 5 6 return [7, 8, 9]; } }, t5: { t6: function (a, b, c) { console.log(a, b, c); // 7 8 9 } } }); 异步任务 var a = 0; tas.await(function(){ a ++; // 1 setTimeout(function(){ a ++; // 2 tas.next(); }, 1000); }); // This task is executed after the previous async task execution is completed. // This proves that all tasks are executed in the order we have written. tas(function(){ a ++ ; // 3 console.log(a); // 3 }) Promise tas.promise(function(){ // Use this.done to pass the data ajax.get('https://api.github.com', this.done); }); tas(function (err, data) { if (err) { console.log(err); } else { console.log(data); } }); 模块化 a.js (dependency) var tas = require('tas'); var a = 0; tas.await(function(){ a ++; // 1 setTimeout(function(){ a ++; // 2 tas.next(); }, 1000); }); tas(function(){ a ++; // 3 }); module.exports = { get: function(){ return a; // 3 } }; b.js (dependency) var tas = require('tas'); var a = 2; tas.await(function(){ a ++; // 3 setTimeout(function(){ a ++; // 4 tas.next(); }, 500); }); tas(function(){ a ++; // 5 }) module.exports = { get: function(){ return a; // 5 } }; calc.js (depends on a.js and b.js) var tas = require('tas'); // The tasks in a.js and b.js are executed in the order we have written. var ma = require('./a'); var mb = require('./b'); // This task will be executed after all tasks are completed. tas(function(){ var a = ma.get(); // 3 var b = mb.get(); // 5 console.log(a + b); // 8 });
...全文
91 回复 打赏 收藏 转发到动态 举报
写回复
用AI写文章
回复
切换为时间正序
请发表友善的回复…
发表回复

476

社区成员

发帖
与我相关
我的任务
社区描述
其他技术讨论专区
其他 技术论坛(原bbs)
社区管理员
  • 其他技术讨论专区社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧