web:fix cannot execute hookAfter in web promise,use setTimeout instead

This commit is contained in:
pengfei.zhou 2021-04-13 18:28:45 +08:00 committed by osborn
parent ace3d30e73
commit 4873ff535d
18 changed files with 140 additions and 1640 deletions

View File

@ -52,9 +52,11 @@ class CounterView extends ViewHolder {
class CounterVM extends ViewModel<CountModel, CounterView> {
onAttached(s: CountModel, vh: CounterView) {
vh.counter.onClick = () => {
Promise.resolve(this.getState().count).then(count => {
this.updateState((state) => {
state.count++;
state.count = count + 1;
});
})
};
}
onBind(s: CountModel, vh: CounterView) {

View File

@ -1171,9 +1171,26 @@ var Panel = /** @class */ (function () {
}
finally { if (e_4) { throw e_4.error; } }
}
if (this.__rendering__) {
//skip
Promise.all(promises).then(function (_) {
});
}
else {
Promise.resolve().then(function () {
this.__rendering__ = true;
Promise.all(promises).then(function (_) {
_this.__rendering__ = false;
_this.onRenderFinished();
});
}
}
else {
if (this.__rendering__) {
//skip
return;
}
this.__rendering__ = true;
Function("return this")().setTimeout(function () {
var e_6, _a, e_7, _b;
if (_this.__root__.isDirty()) {
var model = _this.__root__.toModel();
@ -1209,19 +1226,11 @@ var Panel = /** @class */ (function () {
}
finally { if (e_6) { throw e_6.error; } }
}
});
}
if (this.__rendering__) {
//skip
Promise.all(promises).then(function (_) {
});
}
else {
this.__rendering__ = true;
Promise.all(promises).then(function (_) {
_this.__rendering__ = false;
Promise.all(promises).then(function (_) {
_this.onRenderFinished();
});
}, 0);
}
};
Panel.prototype.onRenderFinished = function () {

View File

@ -890,9 +890,26 @@ class Panel {
}
}
}
if (this.__rendering__) {
//skip
Promise.all(promises).then(_ => {
});
}
else {
Promise.resolve().then(() => {
this.__rendering__ = true;
Promise.all(promises).then(_ => {
this.__rendering__ = false;
this.onRenderFinished();
});
}
}
else {
if (this.__rendering__) {
//skip
return;
}
this.__rendering__ = true;
Function("return this")().setTimeout(() => {
if (this.__root__.isDirty()) {
const model = this.__root__.toModel();
promises.push(this.nativeRender(model));
@ -907,19 +924,11 @@ class Panel {
}
}
}
});
}
if (this.__rendering__) {
//skip
Promise.all(promises).then(_ => {
});
}
else {
this.__rendering__ = true;
Promise.all(promises).then(_ => {
this.__rendering__ = false;
Promise.all(promises).then(_ => {
this.onRenderFinished();
});
}, 0);
}
}
onRenderFinished() {

View File

@ -2389,9 +2389,26 @@ class Panel {
}
}
}
if (this.__rendering__) {
//skip
Promise.all(promises).then(_ => {
});
}
else {
Promise.resolve().then(() => {
this.__rendering__ = true;
Promise.all(promises).then(_ => {
this.__rendering__ = false;
this.onRenderFinished();
});
}
}
else {
if (this.__rendering__) {
//skip
return;
}
this.__rendering__ = true;
Function("return this")().setTimeout(() => {
if (this.__root__.isDirty()) {
const model = this.__root__.toModel();
promises.push(this.nativeRender(model));
@ -2406,19 +2423,11 @@ class Panel {
}
}
}
});
}
if (this.__rendering__) {
//skip
Promise.all(promises).then(_ => {
});
}
else {
this.__rendering__ = true;
Promise.all(promises).then(_ => {
this.__rendering__ = false;
Promise.all(promises).then(_ => {
this.onRenderFinished();
});
}, 0);
}
}
onRenderFinished() {

View File

@ -174,9 +174,26 @@ export class Panel {
}
}
}
if (this.__rendering__) {
//skip
Promise.all(promises).then(_ => {
});
}
else {
Promise.resolve().then(() => {
this.__rendering__ = true;
Promise.all(promises).then(_ => {
this.__rendering__ = false;
this.onRenderFinished();
});
}
}
else {
if (this.__rendering__) {
//skip
return;
}
this.__rendering__ = true;
Function("return this")().setTimeout(() => {
if (this.__root__.isDirty()) {
const model = this.__root__.toModel();
promises.push(this.nativeRender(model));
@ -191,19 +208,11 @@ export class Panel {
}
}
}
});
}
if (this.__rendering__) {
//skip
Promise.all(promises).then(_ => {
});
}
else {
this.__rendering__ = true;
Promise.all(promises).then(_ => {
this.__rendering__ = false;
Promise.all(promises).then(_ => {
this.onRenderFinished();
});
}, 0);
}
}
onRenderFinished() {

View File

@ -196,8 +196,24 @@ export abstract class Panel {
}
}
}
if (this.__rendering__) {
//skip
Promise.all(promises).then(_ => {
})
} else {
Promise.resolve().then(() => {
this.__rendering__ = true
Promise.all(promises).then(_ => {
this.__rendering__ = false
this.onRenderFinished()
})
}
} else {
if (this.__rendering__) {
//skip
return;
}
this.__rendering__ = true
Function("return this")().setTimeout(() => {
if (this.__root__.isDirty()) {
const model = this.__root__.toModel()
promises.push(this.nativeRender(model))
@ -212,18 +228,11 @@ export abstract class Panel {
}
}
}
})
}
if (this.__rendering__) {
//skip
Promise.all(promises).then(_ => {
})
} else {
this.__rendering__ = true
Promise.all(promises).then(_ => {
this.__rendering__ = false
Promise.all(promises).then(_ => {
this.onRenderFinished()
})
}, 0)
}
}
private onRenderFinished() {

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

View File

@ -1,671 +0,0 @@
'use strict';
var doric = require('doric');
const colors = [
"#70a1ff",
"#7bed9f",
"#ff6b81",
"#a4b0be",
"#f0932b",
"#eb4d4b",
"#6ab04c",
"#e056fd",
"#686de0",
"#30336b",
].map(e => doric.Color.parse(e));
var __decorate = (undefined && undefined.__decorate) || function (decorators, target, key, desc) {
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
return c > 3 && r && Object.defineProperty(target, key, r), r;
};
var State;
(function (State) {
State[State["Unspecified"] = 0] = "Unspecified";
State[State["BLACK"] = 1] = "BLACK";
State[State["WHITE"] = 2] = "WHITE";
})(State || (State = {}));
const count = 13;
class AIComputer {
constructor(matrix) {
this.wins = [];
this.winCount = 0;
this.matrix = matrix;
for (let y = 0; y < count; y++) {
for (let x = 0; x < count - 4; x++) {
this.wins.push([]);
for (let k = 0; k < 5; k++) {
this.wins[this.winCount].push({
x: x + k,
y,
});
}
this.winCount++;
}
}
for (let x = 0; x < count; x++) {
for (let y = 0; y < count - 4; y++) {
this.wins.push([]);
for (let k = 0; k < 5; k++) {
this.wins[this.winCount].push({
x,
y: y + k,
});
}
this.winCount++;
}
}
for (let x = 0; x < count - 4; x++) {
for (let y = 0; y < count - 4; y++) {
this.wins.push([]);
for (let k = 0; k < 5; k++) {
this.wins[this.winCount].push({
x: x + k,
y: y + k,
});
}
this.winCount++;
}
}
for (let x = 0; x < count - 4; x++) {
for (let y = count - 1; y > 3; y--) {
this.wins.push([]);
for (let k = 0; k < 5; k++) {
this.wins[this.winCount].push({
x: x + k,
y: y - k,
});
}
this.winCount++;
}
}
}
get blackWins() {
return this.wins.map((win) => {
let idx = 0;
for (let e of win) {
switch (this.matrix.get(e.x + e.y * count)) {
case State.BLACK:
idx++;
break;
case State.WHITE:
return 0;
}
}
return idx;
});
}
get whiteWins() {
return this.wins.map((win) => {
let idx = 0;
for (let e of win) {
switch (this.matrix.get(e.x + e.y * count)) {
case State.WHITE:
idx++;
break;
case State.BLACK:
return 0;
}
}
return idx;
});
}
compute(matrix, role) {
const myScore = new Array(matrix.length).fill(0);
const rivalScore = new Array(matrix.length).fill(0);
const myWins = role === State.BLACK ? this.blackWins : this.whiteWins;
const rivalWins = role === State.BLACK ? this.whiteWins : this.blackWins;
let max = 0;
let retIdx = 0;
matrix.forEach((state, idx) => {
if (state != State.Unspecified) {
return;
}
this.wins.forEach((e, winIdx) => {
if (e.filter(e => (e.x + e.y * count) === idx).length === 0) {
return;
}
switch (rivalWins[winIdx]) {
case 1:
rivalScore[idx] += 1;
break;
case 2:
rivalScore[idx] += 10;
break;
case 3:
rivalScore[idx] += 100;
break;
case 4:
rivalScore[idx] += 10000;
break;
}
switch (myWins[winIdx]) {
case 1:
myScore[idx] += 2;
break;
case 2:
myScore[idx] += 20;
break;
case 3:
myScore[idx] += 200;
break;
case 4:
myScore[idx] += 20000;
break;
}
});
if (rivalScore[idx] > max) {
max = rivalScore[idx];
retIdx = idx;
}
else if (rivalScore[idx] == max) {
if (myScore[idx] > myScore[retIdx]) {
retIdx = idx;
}
}
if (myScore[idx] > max) {
max = myScore[idx];
retIdx = idx;
}
else if (myScore[idx] == max) {
if (rivalScore[idx] > rivalScore[retIdx]) {
retIdx = idx;
}
}
});
return retIdx;
}
}
const lineColor = doric.Color.BLACK;
function columLine() {
return (new doric.Stack).apply({
layoutConfig: doric.layoutConfig().most().configWidth(doric.LayoutSpec.JUST),
width: 1,
backgroundColor: lineColor,
});
}
function rowLine() {
return (new doric.Stack).apply({
layoutConfig: doric.layoutConfig().most().configHeight(doric.LayoutSpec.JUST),
height: 1,
backgroundColor: lineColor,
});
}
function pointer(size) {
return (new doric.Stack).apply({
layoutConfig: doric.layoutConfig().just(),
width: size,
height: size,
});
}
var GameMode;
(function (GameMode) {
GameMode[GameMode["P2P"] = 0] = "P2P";
GameMode[GameMode["P2C"] = 1] = "P2C";
GameMode[GameMode["C2P"] = 2] = "C2P";
})(GameMode || (GameMode = {}));
class GoBangVH extends doric.ViewHolder {
constructor() {
super(...arguments);
this.gap = 0;
this.targetZone = [];
}
build(root) {
this.root = root;
}
actualBuild(state) {
const boardSize = state.gap * (state.count - 1);
const gap = state.gap;
const borderWidth = gap;
this.gap = state.gap;
doric.scroller(doric.vlayout([
doric.text({
text: "五子棋",
layoutConfig: doric.layoutConfig().configWidth(doric.LayoutSpec.MOST),
textSize: 30,
textColor: doric.Color.WHITE,
backgroundColor: colors[0],
textAlignment: doric.gravity().center(),
height: 50,
}),
doric.stack([
doric.stack([
...(new Array(count - 2)).fill(0).map((_, idx) => {
return columLine().also(v => {
v.left = (idx + 1) * gap;
});
}),
...(new Array(count - 2)).fill(0).map((_, idx) => {
return rowLine().also(v => {
v.top = (idx + 1) * gap;
});
}),
])
.apply({
layoutConfig: doric.layoutConfig().just()
.configMargin({ top: borderWidth, left: borderWidth }),
width: boardSize,
height: boardSize,
border: {
width: 1,
color: lineColor,
},
}),
...this.targetZone = (new Array(count * count)).fill(0).map((_, idx) => {
const row = Math.floor(idx / count);
const colum = idx % count;
return pointer(gap).also(v => {
v.top = (row - 0.5) * gap + borderWidth;
v.left = (colum - 0.5) * gap + borderWidth;
});
}),
]).apply({
layoutConfig: doric.layoutConfig().just(),
width: boardSize + 2 * borderWidth,
height: boardSize + 2 * borderWidth,
backgroundColor: doric.Color.parse("#E6B080"),
}),
this.gameMode = doric.text({
text: "游戏模式",
textSize: 20,
textColor: doric.Color.WHITE,
layoutConfig: doric.layoutConfig().most().configHeight(doric.LayoutSpec.JUST),
height: 50,
backgroundColor: colors[8],
}),
doric.hlayout([
this.currentRole = doric.text({
text: "当前:",
textSize: 20,
textColor: doric.Color.WHITE,
layoutConfig: doric.layoutConfig().just().configWeight(1),
height: 50,
backgroundColor: colors[1],
}),
this.result = doric.text({
text: "获胜方:",
textSize: 20,
textColor: doric.Color.WHITE,
layoutConfig: doric.layoutConfig().just().configWeight(1),
height: 50,
backgroundColor: colors[2],
}),
]).apply({
layoutConfig: doric.layoutConfig().fit().configWidth(doric.LayoutSpec.MOST),
}),
this.assistant = doric.text({
text: "提示",
textSize: 20,
textColor: doric.Color.WHITE,
layoutConfig: doric.layoutConfig().just().configWidth(doric.LayoutSpec.MOST),
height: 50,
backgroundColor: colors[3],
}),
])
.apply({
layoutConfig: doric.layoutConfig().fit(),
backgroundColor: doric.Color.parse('#ecf0f1'),
})).in(this.root);
}
}
class GoBangVM extends doric.ViewModel {
onAttached(state, vh) {
if (!this.computer) {
this.computer = new AIComputer(state.matrix);
}
vh.actualBuild(state);
vh.targetZone.forEach((e, idx) => {
e.onClick = () => {
if (state.gameState !== 'idle') {
return;
}
const zoneState = state.matrix.get(idx);
if (zoneState === State.BLACK || zoneState === State.WHITE) {
doric.modal(context).toast('This position had been token.');
return;
}
if (state.anchor === undefined || state.anchor != idx) {
this.updateState(it => {
it.anchor = idx;
});
}
else {
this.updateState(it => {
if (it.role === 'black') {
it.matrix.set(idx, State.BLACK);
it.role = 'white';
}
else {
it.matrix.set(idx, State.WHITE);
it.role = 'black';
}
it.anchor = undefined;
if (this.checkResult(idx)) {
doric.modal(context).toast(`恭喜获胜方${it.role === 'white' ? "黑方" : "白方"}`);
it.gameState = it.role === 'white' ? 'blackWin' : 'whiteWin';
}
else {
if (it.role === 'black' && it.gameMode === GameMode.C2P) {
setTimeout(() => {
this.computeNextStep(it);
}, 0);
}
else if (it.role === 'white' && it.gameMode === GameMode.P2C) {
setTimeout(() => {
this.computeNextStep(it);
}, 0);
}
}
});
}
};
});
vh.gameMode.onClick = () => {
doric.popover(context).show(doric.vlayout([
...[
{
label: "黑方:人 白方:人",
mode: GameMode.P2P,
},
{
label: "黑方:人 白方:机",
mode: GameMode.P2C,
},
{
label: "黑方:机 白方:人",
mode: GameMode.C2P,
},
].map((e) => doric.text({
text: e.label,
textSize: 20,
textColor: doric.Color.WHITE,
layoutConfig: doric.layoutConfig().just(),
height: 50,
width: 300,
backgroundColor: (state.gameMode === e.mode) ? doric.Color.parse('#636e72') : doric.Color.parse('#b2bec3'),
onClick: () => {
this.updateState(s => {
s.gameMode = e.mode;
this.reset(s);
});
doric.popover(context).dismiss();
},
}))
])
.apply({
layoutConfig: doric.layoutConfig().most(),
onClick: () => {
doric.popover(context).dismiss();
},
gravity: doric.Gravity.Center,
}));
};
vh.result.onClick = () => {
switch (state.gameState) {
case "idle":
this.updateState(state => {
this.reset(state);
});
break;
}
};
vh.currentRole.onClick = () => {
switch (state.gameState) {
case "idle":
break;
case "blackWin":
case "whiteWin":
this.updateState(state => {
this.reset(state);
});
break;
}
};
vh.assistant.onClick = () => {
const it = this.getState();
if (it.gameState !== 'idle') {
return;
}
this.computeNextStep(it);
if (it.gameState !== 'idle') {
return;
}
if (it.role === 'black' && it.gameMode === GameMode.C2P) {
setTimeout(() => {
this.computeNextStep(it);
}, 0);
}
else if (it.role === 'white' && it.gameMode === GameMode.P2C) {
setTimeout(() => {
this.computeNextStep(it);
}, 0);
}
};
}
computeNextStep(it) {
const tempMatrix = new Array(count * count).fill(0).map((_, idx) => {
return it.matrix.get(idx) || State.Unspecified;
});
let idx = 0;
do {
idx = this.computer.compute(tempMatrix, it.role === 'black' ? State.BLACK : State.WHITE);
} while (it.matrix.get(idx) === State.Unspecified);
this.updateState(state => {
state.matrix.set(idx, state.role === 'black' ? State.BLACK : State.WHITE);
state.role = state.role === 'black' ? 'white' : 'black';
if (this.checkResult(idx)) {
doric.modal(context).toast(`恭喜获胜方${it.role === 'white' ? "黑方" : "白方"}`);
it.gameState = it.role === 'white' ? 'blackWin' : 'whiteWin';
}
});
}
reset(it) {
it.matrix.clear();
it.gameState = 'idle';
it.role = "black";
it.anchor = undefined;
this.computer = new AIComputer(it.matrix);
if (it.gameMode === GameMode.C2P) {
const idx = Math.floor(Math.random() * count) * count + Math.floor(Math.random() * count);
it.matrix.set(idx, State.BLACK);
it.role = 'white';
}
}
onBind(state, vh) {
vh.targetZone.forEach((v, idx) => {
const zoneState = state.matrix.get(idx);
switch (zoneState) {
case State.BLACK:
v.also(it => {
it.backgroundColor = doric.Color.BLACK;
it.corners = state.gap / 2;
it.border = {
color: doric.Color.TRANSPARENT,
width: 0,
};
});
break;
case State.WHITE:
v.also(it => {
it.backgroundColor = doric.Color.WHITE;
it.corners = state.gap / 2;
it.border = {
color: doric.Color.TRANSPARENT,
width: 0,
};
});
break;
default:
v.also(it => {
it.backgroundColor = doric.Color.TRANSPARENT;
it.corners = 0;
it.border = {
color: doric.Color.TRANSPARENT,
width: 0,
};
});
break;
}
if (state.anchor === idx) {
v.also(it => {
it.backgroundColor = doric.Color.RED.alpha(0.1);
it.corners = 0;
it.border = {
color: doric.Color.RED,
width: 1,
};
});
}
});
vh.gameMode.text = `游戏模式: 黑方 ${state.gameMode === GameMode.C2P ? "机" : "人"} 白方 ${state.gameMode === GameMode.P2C ? "机" : "人"}`;
switch (state.gameState) {
case "idle":
vh.result.text = "重新开始";
vh.currentRole.text = `当前: ${(state.role === 'black') ? "黑方" : "白方"}`;
break;
case "blackWin":
vh.result.text = "黑方获胜";
vh.currentRole.text = "重新开始";
break;
case "whiteWin":
vh.result.text = "白方获胜";
vh.currentRole.text = "重新开始";
break;
}
}
checkResult(pos) {
const matrix = this.getState().matrix;
const state = matrix.get(pos);
const y = Math.floor(pos / count);
const x = pos % count;
const getState = (x, y) => matrix.get(y * count + x);
///Horitonzal
{
let left = x;
while (left >= 1) {
if (getState(left - 1, y) === state) {
left -= 1;
}
else {
break;
}
}
let right = x;
while (right <= count - 2) {
if (getState(right + 1, y) === state) {
right += 1;
}
else {
break;
}
}
if (right - left >= 4) {
return true;
}
}
///Vertical
{
let top = y;
while (top >= 1) {
if (getState(x, top - 1) === state) {
top -= 1;
}
else {
break;
}
}
let bottom = y;
while (bottom <= count - 2) {
if (getState(x, bottom + 1) === state) {
bottom += 1;
}
else {
break;
}
}
if (bottom - top >= 4) {
return true;
}
}
///LT-RB
{
let startX = x, startY = y;
while (startX >= 1 && startY >= 1) {
if (getState(startX - 1, startY - 1) === state) {
startX -= 1;
startY -= 1;
}
else {
break;
}
}
let endX = x, endY = y;
while (endX <= count - 2 && endY <= count - 2) {
if (getState(endX + 1, endY + 1) === state) {
endX += 1;
endY += 1;
}
else {
break;
}
}
if (endX - startX >= 4) {
return true;
}
}
///LB-RT
{
let startX = x, startY = y;
while (startX >= 1 && startY <= count + 2) {
if (getState(startX - 1, startY + 1) === state) {
startX -= 1;
startY += 1;
}
else {
break;
}
}
let endX = x, endY = y;
while (endX <= count - 2 && endY >= 1) {
if (getState(endX + 1, endY - 1) === state) {
endX += 1;
endY -= 1;
}
else {
break;
}
}
if (endX - startX >= 4) {
return true;
}
}
return false;
}
}
let Gobang = class Gobang extends doric.VMPanel {
getViewModelClass() {
return GoBangVM;
}
getState() {
return {
count,
gap: this.getRootView().width / 14,
role: "black",
matrix: new Map,
gameMode: GameMode.P2C,
gameState: "idle"
};
}
getViewHolderClass() {
return GoBangVH;
}
onShow() {
doric.navbar(context).setTitle("五子棋");
}
};
Gobang = __decorate([
Entry
], Gobang);
//# sourceMappingURL=Gobang.js.map

File diff suppressed because one or more lines are too long

View File

@ -1,110 +0,0 @@
'use strict';
var doric = require('doric');
const colors = [
"#70a1ff",
"#7bed9f",
"#ff6b81",
"#a4b0be",
"#f0932b",
"#eb4d4b",
"#6ab04c",
"#e056fd",
"#686de0",
"#30336b",
].map(e => doric.Color.parse(e));
var __decorate = (undefined && undefined.__decorate) || function (decorators, target, key, desc) {
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
return c > 3 && r && Object.defineProperty(target, key, r), r;
};
let ListPanel = class ListPanel extends doric.Panel {
build(rootView) {
let offset = Math.ceil(Math.random() * colors.length);
doric.vlayout([
doric.list({
itemCount: 100,
renderItem: (idx) => {
let counter;
return doric.listItem(doric.hlayout([
doric.text({
layoutConfig: {
widthSpec: doric.LayoutSpec.FIT,
heightSpec: doric.LayoutSpec.JUST,
alignment: doric.gravity().center(),
},
text: `Cell At Line ${idx}`,
textAlignment: doric.gravity().center(),
textColor: doric.Color.parse("#ffffff"),
textSize: 20,
height: 50,
}),
doric.text({
textColor: doric.Color.parse("#ffffff"),
textSize: 20,
text: "",
}).also(it => {
counter = it;
it.layoutConfig = {
widthSpec: doric.LayoutSpec.FIT,
heightSpec: doric.LayoutSpec.FIT,
margin: {
left: 10,
}
};
})
]).also(it => {
it.layoutConfig = {
widthSpec: doric.LayoutSpec.MOST,
heightSpec: doric.LayoutSpec.FIT,
margin: {
bottom: 2,
}
};
it.gravity = doric.gravity().center();
it.backgroundColor = colors[(idx + offset) % colors.length];
let clicked = 0;
it.onClick = () => {
counter.text = `Item Clicked ${++clicked}`;
};
})).also(it => {
it.layoutConfig = {
widthSpec: doric.LayoutSpec.MOST,
heightSpec: doric.LayoutSpec.FIT,
};
it.onClick = () => {
doric.log(`Click item at ${idx}`);
it.height += 10;
it.nativeChannel(context, "getWidth")().then(resolve => {
doric.log(`resolve,${resolve}`);
}, reject => {
doric.log(`reject,${reject}`);
});
};
});
},
layoutConfig: doric.layoutConfig().most().configHeight(doric.LayoutSpec.JUST),
height: 500,
}).also(it => {
it.loadMore = true;
it.onLoadMore = () => {
it.itemCount += 100;
};
it.loadMoreView = doric.listItem(doric.text({
text: "Loading",
layoutConfig: doric.layoutConfig().most().configHeight(doric.LayoutSpec.JUST).configAlignment(doric.Gravity.Center),
height: 50,
}));
}),
]).apply({
layoutConfig: doric.layoutConfig().most(),
}).in(rootView);
}
};
ListPanel = __decorate([
Entry
], ListPanel);
//# sourceMappingURL=ListDemo.js.map

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

View File

@ -2443,9 +2443,26 @@ class Panel {
}
}
}
if (this.__rendering__) {
//skip
Promise.all(promises).then(_ => {
});
}
else {
Promise.resolve().then(() => {
this.__rendering__ = true;
Promise.all(promises).then(_ => {
this.__rendering__ = false;
this.onRenderFinished();
});
}
}
else {
if (this.__rendering__) {
//skip
return;
}
this.__rendering__ = true;
Function("return this")().setTimeout(() => {
if (this.__root__.isDirty()) {
const model = this.__root__.toModel();
promises.push(this.nativeRender(model));
@ -2460,19 +2477,11 @@ class Panel {
}
}
}
});
}
if (this.__rendering__) {
//skip
Promise.all(promises).then(_ => {
});
}
else {
this.__rendering__ = true;
Promise.all(promises).then(_ => {
this.__rendering__ = false;
Promise.all(promises).then(_ => {
this.onRenderFinished();
});
}, 0);
}
}
onRenderFinished() {
@ -5689,7 +5698,7 @@ ${content}
}
function initDoric() {
injectGlobalObject("Environment", {
platform: "h5"
platform: "web"
});
injectGlobalObject("nativeEmpty", () => undefined);
injectGlobalObject('nativeLog', (type, message) => {

File diff suppressed because one or more lines are too long

View File

@ -41,7 +41,7 @@ ${content}
function initDoric() {
injectGlobalObject("Environment", {
platform: "h5"
platform: "web"
})
injectGlobalObject("nativeEmpty", () => undefined)

View File

@ -13,7 +13,7 @@
// "jsx": "preserve", /* Specify JSX code generation: 'preserve', 'react-native', or 'react'. */
// "declaration": true, /* Generates corresponding '.d.ts' file. */
// "declarationMap": true, /* Generates a sourcemap for each corresponding '.d.ts' file. */
// "sourceMap": true, /* Generates corresponding '.map' file. */
"sourceMap": true, /* Generates corresponding '.map' file. */
// "outFile": "./", /* Concatenate and emit output to single file. */
"outDir": "build/", /* Redirect output structure to the directory. */
// "rootDir": "./", /* Specify the root directory of input files. Use to control the output directory structure with --outDir. */