本文整理汇总了TypeScript中common.defined函数的典型用法代码示例。如果您正苦于以下问题:TypeScript defined函数的具体用法?TypeScript defined怎么用?TypeScript defined使用的例子?那么, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了defined函数的10个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的TypeScript代码示例。
示例1: renderMove
export function renderMove(ctx, node): MaybeVNodes {
const ev = node.eval || node.ceval || {};
return [
node.san,
defined(ev.cp) ? renderEval(normalizeEval(ev.cp)) : (
defined(ev.mate) ? renderEval('#' + ev.mate) : null
),
puzzleGlyph(ctx, node)
];
}
示例2: renderMove
export function renderMove(ctx: Ctx, node: Tree.Node): VNode[] {
const ev: any = cevalView.getBestEval({client: node.ceval, server: node.eval}) || {};
return [h('san', fixCrazySan(node.san!))]
.concat((node.glyphs && ctx.showGlyphs) ? renderGlyphs(node.glyphs) : [])
.concat(ctx.showEval ? (
defined(ev.cp) ? [renderEval(normalizeEval(ev.cp))] : (
defined(ev.mate) ? [renderEval('#' + ev.mate)] : []
)
) : []);
}
示例3: addNode
// returns new path
function addNode(node: Tree.Node, path: Tree.Path): Tree.Path | undefined {
const newPath = path + node.id;
var existing = nodeAtPathOrNull(newPath);
if (existing) {
if (defined(node.dests) && !defined(existing.dests)) existing.dests = node.dests;
if (defined(node.drops) && !defined(existing.drops)) existing.drops = node.drops;
return newPath;
}
return updateAt(path, function(parent: Tree.Node) {
parent.children.push(node);
}) ? newPath : undefined;
}
示例4: playerTable
function playerTable(ctrl: AnalyseCtrl, color: Color): VNode {
const d = ctrl.data, trans = ctrl.trans.noarg;
const acpl = d.analysis![color].acpl;
return h('table', {
hook: {
insert(vnode) {
window.lichess.powertip.manualUserIn(vnode.elm);
}
}
}, [
h('thead', h('tr', [
h('td', h('i.is.color-icon.' + color)),
h('th', renderPlayer(ctrl, color))
])),
h('tbody',
advices.map(a => {
const nb: number = d.analysis![color][a[0]];
const attrs: VNodeData = nb ? {
'data-color': color,
'data-symbol': a[2]
} : {};
return h('tr' + (nb ? '.symbol' : ''), { attrs }, [
h('td', '' + nb),
h('th', trans(a[1]))
]);
}).concat(
h('tr', [
h('td', '' + (defined(acpl) ? acpl : '?')),
h('th', trans('averageCentipawnLoss'))
])
))
])
}
示例5:
pvs: e.pvs.map(function(from) {
const to: any = {
moves: from.moves.split(' ')
};
if (defined(from.cp)) to.cp = from.cp;
else to.mate = from.mate;
return to;
}),
示例6: detectThreefold
export function detectThreefold(nodeList, node): void {
if (defined(node.threefold)) return;
const currentFen = threefoldFen(node.fen);
let nbSimilarPositions = 0, i;
for (i in nodeList)
if (threefoldFen(nodeList[i].fen) === currentFen)
nbSimilarPositions++;
node.threefold = nbSimilarPositions > 2;
};
示例7: range
}, range(multiPv).map(function(i) {
if (!pvs[i]) return h('div.pv');
const san = pv2san(instance.variant.key, node.fen, threat, pvs[i].moves.slice(0, 12), pvs[i].mate);
return h('div.pv', threat ? {} : {
attrs: { 'data-uci': pvs[i].moves[0] }
}, [
multiPv > 1 ? h('strong', defined(pvs[i].mate) ? ('#' + pvs[i].mate) : renderEval(pvs[i].cp!)) : null,
h('span', san)
]);
}));
示例8: unselect
li.pubsub.on('analysis.change', (fen: Fen, _, mainlinePly: Ply | false) => {
let chart, point, $chart = $("#adv-chart");
if (fen && fen !== lastFen) {
inputFen.value = fen;
lastFen = fen;
}
if ($chart.length) {
chart = window.Highcharts && $chart.highcharts();
if (chart) {
if (mainlinePly != chart.lastPly) {
if (mainlinePly === false) unselect(chart);
else {
point = chart.series[0].data[mainlinePly - 1 - data.game.startedAtTurn];
if (defined(point)) point.select();
else unselect(chart);
}
}
chart.lastPly = mainlinePly;
}
}
if ($timeChart.length) {
chart = window.Highcharts && $timeChart.highcharts();
if (chart) {
if (mainlinePly != chart.lastPly) {
if (mainlinePly === false) unselect(chart);
else {
const white = mainlinePly % 2 !== 0;
const serie = white ? 0 : 1;
const turn = Math.floor((mainlinePly - 1 - data.game.startedAtTurn) / 2);
point = chart.series[serie].data[turn];
if (defined(point)) point.select();
else unselect(chart);
}
}
chart.lastPly = mainlinePly;
}
}
});
示例9: lastPly
li.pubsub.on('analysis.change', (_fen: string, _path: string, mainlinePly: number | false) => {
if (!li.advantageChart || lastPly() === mainlinePly) return;
const lp = lastPly(typeof mainlinePly === 'undefined' ? lastPly() : mainlinePly),
el = chartEl();
if (el && window.Highcharts) {
const $chart = $(el);
if ($chart.length) {
const chart = $chart.highcharts();
if (chart) {
if (lp === false) unselect(chart);
else {
const point = chart.series[0].data[lp - 1 - root.tree.root.ply];
if (defined(point)) point.select();
else unselect(chart);
}
} else lastPly(false);
}
} else lastPly(false);
});
示例10: toCeval
// from server eval to client eval
function toCeval(e) {
const res: any = {
fen: e.fen,
nodes: e.knodes * 1000,
depth: e.depth,
pvs: e.pvs.map(function(from) {
const to: any = {
moves: from.moves.split(' ')
};
if (defined(from.cp)) to.cp = from.cp;
else to.mate = from.mate;
return to;
}),
cloud: true
};
if (defined(res.pvs[0].cp)) res.cp = res.pvs[0].cp;
else res.mate = res.pvs[0].mate;
res.cloud = true;
return res;
}