From adc60fd88fa9bae8a99681782eb2345b6ee45ee2 Mon Sep 17 00:00:00 2001 From: bergyu Date: Wed, 20 Oct 2021 16:47:47 +0800 Subject: [PATCH] opt some --- proto.js | 2 - publish/client/mp/app.js | 4 +- publish/client/mp/pages/action/action.js | 4 +- publish/client/mp/project.config.json | 158 ++++++++++++----------- publish/client/mp/utils/kit.js | 28 ++-- 5 files changed, 100 insertions(+), 96 deletions(-) diff --git a/proto.js b/proto.js index dc8e63a2..65d38c81 100644 --- a/proto.js +++ b/proto.js @@ -143,10 +143,8 @@ const html = { } const lang = { STRING: "string", OBJECT: "object", FUNCTION: "function", - ENTER: "Enter", } - function shy(help, meta, list, cb) { var index = 0, args = arguments; function next(type) { if (index < args.length && (!type || type == typeof args[index])) { diff --git a/publish/client/mp/app.js b/publish/client/mp/app.js index 17a1ccf4..334e36ba 100644 --- a/publish/client/mp/app.js +++ b/publish/client/mp/app.js @@ -3,7 +3,7 @@ const kit = require("utils/kit.js") App({ data: {}, conf: {serve: "https://shylinux.com/chat", space: ""}, requests: function(cmd, data, cb) { wx.showLoading() - this.request(cmd, data, function(msg) { wx.hideLoading(), can.base.isFunc(cb) && cb(msg) }) + this.request(cmd, data, function(msg) { wx.hideLoading(), typeof cb == "function" && cb(msg) }) }, request: function(cmd, data, cb) { var app = this; data.sessid = app.conf.sessid, data.pod = app.conf.space wx.request({method: "POST", url: app.conf.serve+"/"+cmd, data: data, success: function(res) { var msg = res.data @@ -22,7 +22,7 @@ App({ var line = {}; kit.List(msg.key, function(key, index) { line[key] = msg.value[index] }) - can.base.isFunc(cb) && cb(line, 0, 1) + typeof cb == "function" && cb(line, 0, 1) return res.push(line), res } diff --git a/publish/client/mp/pages/action/action.js b/publish/client/mp/pages/action/action.js index b0a70cfc..82df9977 100644 --- a/publish/client/mp/pages/action/action.js +++ b/publish/client/mp/pages/action/action.js @@ -106,7 +106,7 @@ Page({ case "刷新": // 执行命令 case "list": page.run(event, data.order); break default: - var cb = page.plugin[input.name]; can.base.isFunc(cb)? cb(event, page, data.order, input.name): + var cb = page.plugin[input.name]; typeof cb == "function"? cb(event, page, data.order, input.name): page.run(event, data.order, ["action", input.name].concat(kit.List(field.inputs, function(input) { if (input.type != "button") { return input.value } }))) @@ -124,7 +124,7 @@ Page({ } event._option = option - var cb = page.plugin[input.name]; can.base.isFunc(cb)? cb(event, page, data.order, input.name): + var cb = page.plugin[input.name]; typeof cb == "function"? cb(event, page, data.order, input.name): page.run(event, data.order, ["action", input.name]) return } diff --git a/publish/client/mp/project.config.json b/publish/client/mp/project.config.json index c0e12128..92b27508 100644 --- a/publish/client/mp/project.config.json +++ b/publish/client/mp/project.config.json @@ -1,80 +1,82 @@ { - "description": "项目配置文件", - "packOptions": { - "ignore": [] - }, - "setting": { - "urlCheck": true, - "es6": true, - "enhance": false, - "postcss": true, - "preloadBackgroundData": false, - "minified": true, - "newFeature": true, - "coverView": true, - "nodeModules": false, - "autoAudits": false, - "showShadowRootInWxmlPanel": true, - "scopeDataCheck": false, - "uglifyFileName": false, - "checkInvalidKey": true, - "checkSiteMap": true, - "uploadWithSourceMap": true, - "compileHotReLoad": false, - "useMultiFrameRuntime": false, - "useApiHook": true, - "babelSetting": { - "ignore": [], - "disablePlugins": [], - "outputPath": "" - }, - "enableEngineNative": false, - "bundle": false, - "useIsolateContext": true, - "useCompilerModule": true, - "userConfirmedUseCompilerModuleSwitch": false, - "userConfirmedBundleSwitch": false, - "packNpmManually": false, - "packNpmRelationList": [], - "minifyWXSS": true - }, - "compileType": "miniprogram", - "libVersion": "2.15.0", - "appid": "wxf4e5104d83476ed6", - "projectname": "%E7%BB%88%E7%AB%AF%E5%B7%A5%E5%85%B7%E9%93%BE", - "debugOptions": { - "hidedInDevtools": [] - }, - "isGameTourist": false, - "simulatorType": "wechat", - "simulatorPluginLibVersion": {}, - "condition": { - "search": { - "list": [] - }, - "conversation": { - "list": [] - }, - "plugin": { - "list": [] - }, - "game": { - "currentL": -1, - "list": [] - }, - "gamePlugin": { - "list": [] - }, - "miniprogram": { - "list": [ - { - "id": 0, - "name": "pages/action/action", - "pathName": "pages/action/action", - "query": "river= e0a1eb&storm=c23ae3&title=hi.scan", - "scene": 1001 - } - ] - } - } + "description": "项目配置文件", + "packOptions": { + "ignore": [] + }, + "setting": { + "urlCheck": true, + "es6": true, + "enhance": false, + "postcss": true, + "preloadBackgroundData": false, + "minified": true, + "newFeature": true, + "coverView": true, + "nodeModules": false, + "autoAudits": false, + "showShadowRootInWxmlPanel": true, + "scopeDataCheck": false, + "uglifyFileName": false, + "checkInvalidKey": true, + "checkSiteMap": true, + "uploadWithSourceMap": true, + "compileHotReLoad": false, + "lazyloadPlaceholderEnable": false, + "useMultiFrameRuntime": true, + "useApiHook": true, + "useApiHostProcess": true, + "babelSetting": { + "ignore": [], + "disablePlugins": [], + "outputPath": "" + }, + "enableEngineNative": false, + "useIsolateContext": true, + "userConfirmedBundleSwitch": false, + "packNpmManually": false, + "packNpmRelationList": [], + "minifyWXSS": true, + "disableUseStrict": false, + "showES6CompileOption": false, + "useCompilerPlugins": false + }, + "compileType": "miniprogram", + "libVersion": "2.15.0", + "appid": "wxf4e5104d83476ed6", + "projectname": "%E7%BB%88%E7%AB%AF%E5%B7%A5%E5%85%B7%E9%93%BE", + "debugOptions": { + "hidedInDevtools": [] + }, + "isGameTourist": false, + "simulatorType": "wechat", + "simulatorPluginLibVersion": {}, + "condition": { + "search": { + "list": [] + }, + "conversation": { + "list": [] + }, + "plugin": { + "list": [] + }, + "game": { + "currentL": -1, + "list": [] + }, + "gamePlugin": { + "list": [] + }, + "miniprogram": { + "list": [ + { + "id": 0, + "name": "pages/action/action", + "pathName": "pages/action/action", + "query": "river= e0a1eb&storm=c23ae3&title=hi.scan", + "scene": 1001 + } + ] + } + } } \ No newline at end of file diff --git a/publish/client/mp/utils/kit.js b/publish/client/mp/utils/kit.js index e0fdcdc8..3f31d4e7 100644 --- a/publish/client/mp/utils/kit.js +++ b/publish/client/mp/utils/kit.js @@ -1,16 +1,20 @@ +const lang = { + STRING: "string", OBJECT: "object", FUNCTION: "function", + ENTER: "Enter", +} function shy(help, meta, list, cb) { - var index = 0, args = arguments; function next(check) { - if (index < args.length && (!check || check == typeof args[index])) { + var index = 0, args = arguments; function next(type) { + if (index < args.length && (!type || type == typeof args[index])) { return args[index++] } } - cb = args[args.length-1] || function() {} - cb.help = next("string") || "" - cb.meta = next("object") || {} - cb.list = next("object") || [] + cb = args[args.length-1]||function() {} + cb.help = next(lang.STRING)||"" + cb.meta = next(lang.OBJECT)|| {} + cb.list = next(lang.OBJECT)||[] return cb -}; var _can_name = "" +} module.exports = { EQ: function(obj, other) { if (typeof obj != typeof other) { return false } @@ -51,9 +55,9 @@ module.exports = { }, List: function(list, cb, cbs) {var res = [], val; for (var i = 0; i < list.length; i++) { - can.base.isFunc(cb)? (val = cb(list[i], i, list)) != undefined && res.push(val): res.push(list[i]) + typeof cb == "function"? (val = cb(list[i], i, list)) != undefined && res.push(val): res.push(list[i]) } - return can.base.isFunc(cbs) && cbs(res), res + return typeof cbs == "function" && cbs(res), res }, Item: function(list, cb, cbs) { for (var k in list) { cb(k, list[k]) } @@ -93,10 +97,10 @@ module.exports = { interval = typeof interval == "object"? interval || []: [interval] var timer = {stop: false}; function loop(timer, i) { if (timer.stop || i >= interval.length && interval.length >= 0) { - return can.base.isFunc(cbs) && cbs(timer, interval) + return typeof cbs == "function" && cbs(timer, interval) } - return can.base.isFunc(cb) && cb(timer, interval.interval||interval[i], i, interval)? - can.base.isFunc(cbs) && cbs(timer, interval): setTimeout(function() { loop(timer, i+1) }, interval.interval||interval[i+1]) + return typeof cb == "function" && cb(timer, interval.interval||interval[i], i, interval)? + typeof cbs == "function" && cbs(timer, interval): setTimeout(function() { loop(timer, i+1) }, interval.interval||interval[i+1]) } setTimeout(function() { loop(timer, 0) }, interval.interval||interval[0]) return timer