Commit ab3b0784 authored by rockyl's avatar rockyl

优化mvvm编译

parent 96c534b8
...@@ -2007,7 +2007,7 @@ var tslib = {__extends: __extends,__assign: __assign,__rest: __rest,__decorate: ...@@ -2007,7 +2007,7 @@ var tslib = {__extends: __extends,__assign: __assign,__rest: __rest,__decorate:
var cmdOldPrefix = '//z-'; var cmdOldPrefix = '//z-';
function injectProperties(target, source) { function injectProperties(target, source) {
for (var key in source) { for (var key in source) {
if (!source.hasOwnProperty(cmdPrefix + key)) { if (key.indexOf('//') !== 0 && !source.hasOwnProperty(cmdPrefix + key)) {
propertyParse(key, target, source); propertyParse(key, target, source);
} }
} }
...@@ -2026,7 +2026,6 @@ var tslib = {__extends: __extends,__assign: __assign,__rest: __rest,__decorate: ...@@ -2026,7 +2026,6 @@ var tslib = {__extends: __extends,__assign: __assign,__rest: __rest,__decorate:
} }
} }
} }
//# sourceMappingURL=utils.js.map
function transPoint(str, sep) { function transPoint(str, sep) {
if (sep === void 0) { sep = ','; } if (sep === void 0) { sep = ','; }
...@@ -20147,40 +20146,44 @@ var tslib = {__extends: __extends,__assign: __assign,__rest: __rest,__decorate: ...@@ -20147,40 +20146,44 @@ var tslib = {__extends: __extends,__assign: __assign,__rest: __rest,__decorate:
ZriCompiler.prototype.compile = function (target, scope) { ZriCompiler.prototype.compile = function (target, scope) {
var cmdDatas = []; var cmdDatas = [];
var needInterrupt = false; var needInterrupt = false;
for (var key in target) { var originConfig = target['__originConfig'];
if (key.indexOf(cmdPrefix) < 0) { if (originConfig && originConfig.properties) {
continue; var properties = originConfig.properties;
for (var key in properties) {
if (key.indexOf(cmdPrefix) != 0) {
continue;
}
var cmdData = this._entity.parseCommand(key, target[key]);
if (cmdData) {
cmdDatas.push(cmdData);
if (interruptCmds.indexOf(cmdData.cmdName) >= 0) {
needInterrupt = true;
cmdDatas.splice(0, cmdDatas.length - 1);
break;
}
}
} }
var cmdData = this._entity.parseCommand(key, target[key]); for (var _i = 0, cmdDatas_1 = cmdDatas; _i < cmdDatas_1.length; _i++) {
if (cmdData) { var cmdData = cmdDatas_1[_i];
cmdDatas.push(cmdData); delete target[cmdData.propName];
if (interruptCmds.indexOf(cmdData.cmdName) >= 0) { if (interruptCmds.indexOf(cmdData.cmdName) >= 0) {
needInterrupt = true; delete properties[cmdData.propName];
cmdDatas.splice(0, cmdDatas.length - 1); }
break; var cmd = commands$1[cmdData.cmdName];
if (!cmd) {
cmdData.subCmd = cmdData.cmdName || "";
cmdData.cmdName = "prop";
cmd = commands$1[cmdData.cmdName];
} }
cmd({
scope: scope,
target: target,
entity: this._entity,
cmdData: cmdData,
compiler: this,
});
} }
} }
for (var _i = 0, cmdDatas_1 = cmdDatas; _i < cmdDatas_1.length; _i++) {
var cmdData = cmdDatas_1[_i];
delete target[cmdData.propName];
if (interruptCmds.indexOf(cmdData.cmdName) >= 0 && target['__originConfig']) {
delete target['__originConfig'].properties[cmdData.propName];
}
var cmd = commands$1[cmdData.cmdName];
if (!cmd) {
cmdData.subCmd = cmdData.cmdName || "";
cmdData.cmdName = "prop";
cmd = commands$1[cmdData.cmdName];
}
cmd({
scope: scope,
target: target,
entity: this._entity,
cmdData: cmdData,
compiler: this,
});
}
if (!needInterrupt && target.children && target.children.length > 0) { if (!needInterrupt && target.children && target.children.length > 0) {
for (var _a = 0, _b = target.children; _a < _b.length; _a++) { for (var _a = 0, _b = target.children; _a < _b.length; _a++) {
var child = _b[_a]; var child = _b[_a];
...@@ -20188,13 +20191,17 @@ var tslib = {__extends: __extends,__assign: __assign,__rest: __rest,__decorate: ...@@ -20188,13 +20191,17 @@ var tslib = {__extends: __extends,__assign: __assign,__rest: __rest,__decorate:
} }
} }
}; };
ZriCompiler.prototype.debug = function () {
};
return ZriCompiler; return ZriCompiler;
}()); }());
//# sourceMappingURL=ZriCompiler.js.map //# sourceMappingURL=ZriCompiler.js.map
function bind(store, view, options) { function bind(store, view, options) {
var compiler = new ZriCompiler(view); var compiler = new ZriCompiler(view);
return new Zri(store, compiler, options); var zri = new Zri(store, compiler, options);
compiler.debug();
return zri;
} }
function createStore(exp, computed) { function createStore(exp, computed) {
var store = safeEval(exp) || {}; var store = safeEval(exp) || {};
......
This source diff could not be displayed because it is too large. You can view the blob instead.
{"id":"engine","url":"engine.a00613f119b951548555b2f0d7ddcd5063975f8e.js"} {"id":"engine","url":"engine.3792fc7af6815b498e54518f48fb3d29a80d61f7.js"}
\ No newline at end of file \ No newline at end of file
...@@ -30,7 +30,8 @@ ...@@ -30,7 +30,8 @@
"build:debug": "rm -rf dist&&yarn build && yarn preprocess && ali-oss-publish -c oss.config.js -e dist", "build:debug": "rm -rf dist&&yarn build && yarn preprocess && ali-oss-publish -c oss.config.js -e dist",
"ts": "dts-bundle --name engine --main types/src/index.d.ts --out ../../dist/index.d.ts", "ts": "dts-bundle --name engine --main types/src/index.d.ts --out ../../dist/index.d.ts",
"test": "echo \"Error: no test specified\" && exit 1", "test": "echo \"Error: no test specified\" && exit 1",
"mergeDts": "node scripts/mergeDts.js" "mergeDts": "node scripts/mergeDts.js",
"token": "uglifyjs -m -c -o px-token.min.js px-token.js"
}, },
"author": "", "author": "",
"license": "ISC" "license": "ISC"
......
...@@ -9,7 +9,17 @@ function getPxToken(callback) { ...@@ -9,7 +9,17 @@ function getPxToken(callback) {
window.eval(response.data); window.eval(response.data);
callback(null, window['ohjaiohdf']()); callback(null, window['ohjaiohdf']());
} else { } else {
callback('state invalid'); switch(response.code){
case '100001':
callback('need login');
break;
case '100024':
callback('state invalid');
break;
default:
callback(response.code);
break;
}
} }
} }
}; };
......
...@@ -743,15 +743,15 @@ export class TextField extends Sprite { ...@@ -743,15 +743,15 @@ export class TextField extends Sprite {
const texture = this._texture; const texture = this._texture;
const baseTexture = texture.baseTexture; const baseTexture = texture.baseTexture;
baseTexture.hasLoaded = canvas.width && canvas.height ? true : false; baseTexture.hasLoaded = canvas.width && canvas.height ? true : false;
baseTexture.width = canvas.width baseTexture.width = canvas.width;
baseTexture.height = canvas.height baseTexture.height = canvas.height;
//texture,已绑定过尺寸改变onBaseTextureUpdated //texture,已绑定过尺寸改变onBaseTextureUpdated
baseTexture.dispatchEvent('update'); baseTexture.dispatchEvent('update');
texture.valid = baseTexture.hasLoaded; texture.valid = baseTexture.hasLoaded;
texture._frame.width = canvas.width texture._frame.width = canvas.width;
texture._frame.height = canvas.height; texture._frame.height = canvas.height;
texture.orig.width = texture._frame.width texture.orig.width = texture._frame.width;
texture.orig.height = texture._frame.height texture.orig.height = texture._frame.height;
} }
......
...@@ -2,7 +2,7 @@ ...@@ -2,7 +2,7 @@
* Created by rockyl on 2020-03-19. * Created by rockyl on 2020-03-19.
*/ */
import {Compiler, IZri, ZriCommandData} from "./Interfaces"; import {Compiler, IZri, ZriCommandData} from "./Interfaces";
import {Container, } from "../../../2d/display/index"; import {Container,} from "../../../2d/display/index";
import {Command, commands, CommandContext} from "./ZriCommands"; import {Command, commands, CommandContext} from "./ZriCommands";
import {cmdPrefix} from "../../utils/utils"; import {cmdPrefix} from "../../utils/utils";
...@@ -25,41 +25,53 @@ export class ZriCompiler implements Compiler { ...@@ -25,41 +25,53 @@ export class ZriCompiler implements Compiler {
this.compile(this._root, entity.data); this.compile(this._root, entity.data);
} }
//props = [];
compile(target: any, scope: any): void { compile(target: any, scope: any): void {
let cmdDatas = []; let cmdDatas = [];
let needInterrupt = false; let needInterrupt = false;
for (let key in target) { let originConfig = target['__originConfig'];
if(key.indexOf(cmdPrefix) < 0){ if (originConfig && originConfig.properties) {
continue; let properties = originConfig.properties;
} let props = [];
let cmdData = this._entity.parseCommand(key, target[key]); for (let key in properties) {
if (cmdData) { if (key.indexOf(cmdPrefix) != 0) {
cmdDatas.push(cmdData); continue;
if(interruptCmds.indexOf(cmdData.cmdName) >= 0){ }
needInterrupt = true; //props.push(key);
cmdDatas.splice(0, cmdDatas.length - 1); let cmdData = this._entity.parseCommand(key, target[key]);
break; if (cmdData) {
cmdDatas.push(cmdData);
if (interruptCmds.indexOf(cmdData.cmdName) >= 0) {
needInterrupt = true;
cmdDatas.splice(0, cmdDatas.length - 1);
break;
}
} }
} }
} for (let cmdData of cmdDatas) {
for (let cmdData of cmdDatas) { delete target[cmdData.propName];
delete target[cmdData.propName]; if (interruptCmds.indexOf(cmdData.cmdName) >= 0) {
if (interruptCmds.indexOf(cmdData.cmdName) >= 0 && target['__originConfig']) { delete properties[cmdData.propName];
delete target['__originConfig'].properties[cmdData.propName]; }
} let cmd: Command = commands[cmdData.cmdName];
let cmd: Command = commands[cmdData.cmdName]; if (!cmd) {
if (!cmd) { cmdData.subCmd = cmdData.cmdName || "";
cmdData.subCmd = cmdData.cmdName || ""; cmdData.cmdName = "prop";
cmdData.cmdName = "prop"; cmd = commands[cmdData.cmdName];
cmd = commands[cmdData.cmdName]; }
cmd({
scope,
target,
entity: this._entity,
cmdData,
compiler: this,
})
} }
cmd({
scope, /*if(props.length > 0){
target, this.props.push(props);
entity: this._entity, }*/
cmdData,
compiler: this,
})
} }
if (!needInterrupt && target.children && target.children.length > 0) { if (!needInterrupt && target.children && target.children.length > 0) {
for (let child of target.children) { for (let child of target.children) {
...@@ -67,4 +79,8 @@ export class ZriCompiler implements Compiler { ...@@ -67,4 +79,8 @@ export class ZriCompiler implements Compiler {
} }
} }
} }
debug() {
//console.log(this.props);
}
} }
...@@ -17,7 +17,9 @@ import {safeEval} from "../../utils/utils"; ...@@ -17,7 +17,9 @@ import {safeEval} from "../../utils/utils";
*/ */
export function bind(store: any, view: Container, options?: ZriOptions): IZri { export function bind(store: any, view: Container, options?: ZriOptions): IZri {
let compiler = new ZriCompiler(view); let compiler = new ZriCompiler(view);
return new Zri(store, compiler, options); let zri = new Zri(store, compiler, options);
compiler.debug();
return zri;
} }
/** /**
......
...@@ -329,7 +329,7 @@ export const cmdOldPrefix = '//z-'; ...@@ -329,7 +329,7 @@ export const cmdOldPrefix = '//z-';
*/ */
export function injectProperties(target, source) { export function injectProperties(target, source) {
for (let key in source) { for (let key in source) {
if(!source.hasOwnProperty(cmdPrefix + key)){ if(key.indexOf('//') !== 0 && !source.hasOwnProperty(cmdPrefix + key)){
propertyParse(key, target, source); propertyParse(key, target, source);
} }
} }
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment