本文整理汇总了TypeScript中lodash.result函数的典型用法代码示例。如果您正苦于以下问题:TypeScript result函数的具体用法?TypeScript result怎么用?TypeScript result使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了result函数的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的TypeScript代码示例。
示例1: explainTransaction
/**
* Explain/parse transaction
* @param params
* - txBase64: transaction encoded as base64 string
* @returns {{displayOrder: [string,string,string,string,string], id: *, outputs: Array, changeOutputs: Array}}
*/
explainTransaction(params) {
const { txBase64 } = params;
let tx;
try {
tx = new stellar.Transaction(txBase64);
} catch (e) {
throw new Error('txBase64 needs to be a valid tx encoded as base64 string');
}
const id = tx.hash().toString('hex');
const explanation: any = {
displayOrder: ['id', 'outputAmount', 'changeAmount', 'outputs', 'changeOutputs', 'fee', 'memo'],
id,
outputs: [],
changeOutputs: [],
memo: {}
};
// In a Stellar tx, the _memo property is an object with the methods:
// value() and arm() that provide memo value and type, respectively.
if (_.result(tx, '_memo.value') && _.result(tx, '_memo.arm')) {
explanation.memo = {
value: _.result(tx, '_memo.value').toString(),
type: _.result(tx, '_memo.arm')
};
}
let spendAmount = new BigNumber(0);
// Process only operations of the native asset (XLM)
const operations = _.filter(tx.operations, operation => !operation.asset || operation.asset.getCode() === 'XLM');
if (_.isEmpty(operations)) {
throw new Error('missing operations');
}
explanation.outputs = _.map(operations, operation => {
// Get memo to attach to address, if type is 'id'
const memoId = (_.get(explanation, 'memo.type') === 'id' && ! _.get(explanation, 'memo.value') ? `?memoId=${explanation.memo.value}` : '');
const output = {
amount: this.bigUnitsToBaseUnits(operation.startingBalance || operation.amount),
address: operation.destination + memoId
};
spendAmount = spendAmount.plus(output.amount);
return output;
});
explanation.outputAmount = spendAmount.toFixed(0);
explanation.changeAmount = '0';
explanation.fee = {
fee: tx.fee.toFixed(0),
feeRate: null,
size: null
};
return explanation;
}
示例2: handleError
static handleError(err, res, config: Config) {
var error = new Error(get(res, 'body.description') || get(err, 'response.statusText') || 'No error details available')
if (res) {
error['headers'] = res.headers
error['object'] = res.body
error['statusCode'] = res.statusCode
error['statusText'] = res.statusText
error['url'] = res.req.url
error['method'] = res.req.method
error['stack'] = err.stack
}
else {
const errMsg = result(err, 'toString')
error['statusCode'] = 500
error['statusText'] = errMsg || 'Unknown error'
}
// session timed out, reset cookies and caches
if (error['statusCode'] === 419) {
Cache.instance.clear()
config.clear()
}
if (config.settings.errorInterceptor) {
if (config.settings.errorInterceptor(error)) return [true, error]
}
return [false, error]
}
示例3:
.reduce(function(colorActions: ILineColorAction[], astNode: ILambdaScriptAstNode) {
const color = colorMap[astNode.type];
if (color) {
const colorFn = chalk[color].bind(chalk),
locKey = alternateLocMap[astNode.type] || 'loc',
// I'm just using _.result to avoid TS7017
loc: ILoc = _.result(astNode, locKey);
/**
* Originally, I just colored as soon as I found a node. However, this does not work,
* because other coloring may have occurred on the line already, which will offset our
* column indices. And it is not sufficient just to drop all color from the line and
* see what the length difference is, because some of that color could be *after* our
* column indices and thus irrelevant. To solve this, we will gather all the colorings
* we want to do, and then apply them in sorted order. This makes the offset caclulation trivial.
*/
return colorActions.concat({
// I don't know why but jison does not 0-index the line number.
lineIndex: loc.first_line - 1,
colStart: loc.first_column,
colEnd: loc.last_column,
colorFn: colorFn
});
}
return colorActions;
}, []),
示例4: handlePolling
export function handlePolling(url: string, settings: any, sendRequest: (url: string, settings: any) => any)
: Promise<ApiResponse> {
const pollingDelay: number = result(settings, 'pollDelay');
return new Promise((resolve, reject) => {
setTimeout(() => {
sendRequest(url, settings).then(resolve, reject);
}, pollingDelay);
});
}
示例5: it
it('hashmap pode ter funçþes como propriedades', () => {
let hash: any = {
a: 'algum valor',
b(): number {
return 10;
}
}
expect(hash.b()).to.equal(10);
expect(_.result(hash, 'b')).to.equal(10);
});
示例6: constructor
constructor(public appState: AppState) {
this.currentLang = _.result(appState, "get('lang')", 'en_US');
}
示例7: return
export const renderWhenTrue = (Component: JSX.Element | (() => JSX.Element)) => (trueStatement) => {
return (trueStatement ? result({ Component }, 'Component') : null) as JSX.Element | JSX.Element[];
};