From 4a04a8f5b4dcf6be77be3ce74dd1464eeb43aa95 Mon Sep 17 00:00:00 2001 From: shaoying Date: Mon, 11 May 2020 08:37:11 +0800 Subject: [PATCH] add engine --- frame.js | 60 +++++++++++++++++++++++++++++++++++++++++++++++++++++++- proto.js | 12 ++++++------ 2 files changed, 65 insertions(+), 7 deletions(-) diff --git a/frame.js b/frame.js index b46df9f3..f4296bd8 100644 --- a/frame.js +++ b/frame.js @@ -6,6 +6,23 @@ Volcanos("onaction", { _init: function(can, meta, list, cb, target) { }, can[item.name] = pane, next(); }, can._target); }, function() { can.onlayout._init(can, meta, list, function() { + function getAction() {} + function getStorm(storm) { can.core.Item(storm, function(key, value) { + value._link? can.require([value._link], function(can) { + }, function(can, name, sub) { + getAction(value.action = sub.action) + return true + }): getAction(value.action) + }) } + function getRiver(river) { can.core.Item(river, function(key, value) { + value._link? can.require([value._link], function(can) { + }, function(can, name, sub) { + getStorm(value.storm = sub.storm) + return true + }): getStorm(value.storm) + }) } + can.onengine && getRiver(can.onengine.river) + var pane = can[meta.main.name], msg = can.request(can._event); pane.onaction._init(pane, msg, msg.option||[], cb, target); }, target) }); @@ -17,8 +34,49 @@ Volcanos("onaction", { _init: function(can, meta, list, cb, target) { typeof fun == "function" && fun(sub, msg, cmds.slice(2), cb, sub._target) }, + engine: function(event, can, msg, pane, cmds, cb) { + switch (pane._name) { + case "River": + if (cmds.length == 0) { + can.core.Item(can.onengine.river, function(key, value) { + msg.Push("key", key) + msg.Push("name", value.name) + }) + } + break + case "Storm": + var river = can.onengine.river[cmds[0]] + if (!river) { break } + can.core.Item(river.storm, function(key, value) { + msg.Push("key", key) + msg.Push("name", value.name) + }) + typeof cb == "function" && cb(msg) + return true + case "Action": + var river = can.onengine.river[cmds[0]]; + var storm = river && river.storm[cmds[1]]; + var action = storm && storm.action[cmds[2]]; + if (!storm) { break } if (cmds.length == 2) { + can.core.List(storm.action, function(value) { + msg.Push("name", value.name||""); + msg.Push("help", value.help||""); + msg.Push("inputs", JSON.stringify(value.inputs||[])); + }) + typeof cb == "function" && cb(msg); + } else if (action.engine) { + action.engine(event, can, msg, pane, cmds, cb); + } else { + msg.Option("group", action.group) + msg.Option("index", action.index) + return false + } + return true + } + return false; + }, remote: function(event, can, msg, pane, cmds, cb) { - if (can.onengine && can.onengine.remote(event, can, msg, pane, cmds, cb)) { return } + if (can.onaction.engine(event, can, msg, pane, cmds, cb)) { return } if (location.protocol == "file:") { typeof cb == "function" && cb(msg); return } can.misc.Run(event, can, {names: pane._name}, cmds, cb) }, diff --git a/proto.js b/proto.js index 4a867ce4..d9bbb4b7 100644 --- a/proto.js +++ b/proto.js @@ -25,7 +25,7 @@ var Volcanos = shy("火山架", {cache: {}, index: 1, order: 1, debug: { var conf = {}, conf_cb = {}, sync = {}, cache = {}; meta.debug[can._root] && console.debug(can._root, name, "create"); - can = can || {}, list.push(can) && (can.__proto__ = { _name: name, _root: "volcano", _create_time: new Date(), _load: function(name) { + can = can || {}, list.push(can) && (can.__proto__ = { _name: name, _root: "volcano", _create_time: new Date(), _load: function(name, cb) { for (var cache = meta.cache[name] || []; meta.index < list.length; meta.index++) { if (list[meta.index] == can) {continue} meta.debug["cache"] && console.debug("cache", name, "load", meta.index, list[meta.index]); @@ -35,18 +35,18 @@ var Volcanos = shy("火山架", {cache: {}, index: 1, order: 1, debug: { for (var i = 0; i < cache.length; i++) { meta.debug["frame"] && console.debug("frame", can._name, "load", i, cache[i]); - can[cache[i]._name] = cache[i]; + typeof cb == "function" && cb(can, name, cache[i]) || (can[cache[i]._name] = cache[i]); // 加载索引 } meta.cache[name] = cache; }, - require: function(libs, cb) { if (!libs || libs.length == 0) { + require: function(libs, cb, each) { if (!libs || libs.length == 0) { typeof cb == "function" && setTimeout(function() {cb(can)}, 10); return // 加载完成 } meta.debug["require"] && console.debug(can._root, can._name, "require", libs[0]); if (meta.cache[libs[0]]) { - can._load(libs[0]), can.require(libs.slice(1), cb); + can._load(libs[0], each), can.require(libs.slice(1), cb, each); return // 缓存加载 } @@ -55,14 +55,14 @@ var Volcanos = shy("火山架", {cache: {}, index: 1, order: 1, debug: { if (source.endsWith(".js")) { var script = document.createElement("script"); script.src = source, script.onload = function() { - can._load(libs[0]), can.require(libs.slice(1), cb); + can._load(libs[0], each), can.require(libs.slice(1), cb, each); } // 加载脚本 target.appendChild(script); } else if (source.endsWith(".css")) { var style = document.createElement("link"); style.rel = "stylesheet", style.type = "text/css"; style.href = source; style.onload = function() { - can._load(libs[0]), can.require(libs.slice(1), cb); + can._load(libs[0], each), can.require(libs.slice(1), cb, each); } // 加载样式 target.appendChild(style); }