本文整理汇总了TypeScript中lodash.valuesIn函数的典型用法代码示例。如果您正苦于以下问题:TypeScript valuesIn函数的具体用法?TypeScript valuesIn怎么用?TypeScript valuesIn使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了valuesIn函数的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的TypeScript代码示例。
示例1: fieldMap
export function insertQuery<F> (v: Model<F> | IResourceObject) {
const id = v.id
if (!id) {
throw ErrIDRequired
}
const map = fieldMap(v, { id })
return SqlString.format(
`INSERT INTO ?? (??) VALUES (?);`,
[ tableName(v), _.keysIn(map), _.valuesIn(map) ]
)
}
示例2: it
it("delete Widget", function () {
const store = Store.createEmpty({log: false});
store.dispatch(Widgets.addWidget("my-widget-type", {foo: "bar"}, 1, 2, 3, 4));
assert.equal(_.keysIn(store.getState().widgets).length, 1);
_.valuesIn(store.getState().widgets).forEach((widget: Widgets.IWidgetState) => {
store.dispatch(Widgets.deleteWidget(widget.id));
});
assert.equal(_.keysIn(store.getState().widgets).length, 0);
});
示例3: getParticipantEthFees
async function getParticipantEthFees(db: Knex, augur: Augur, reporter: Address, universe: Address): Promise<Array<ParticipantEthFee>> {
const participantQuery = db
.select([
"participantAddress",
"feeToken.feeWindow",
"feeToken.token as feeToken",
"reporterBalance",
"participantSupply",
"forking",
"reputationToken",
"reputationTokenBalance",
db.raw("IFNULL(feeToken.balance,0) as feeTokenBalance"),
db.raw("IFNULL(feeToken.supply,0) as feeTokenSupply"),
db.raw("IFNULL(cashFeeWindow.balance,0) as cashFeeWindow"),
db.raw("IFNULL(cashParticipant.balance,0) as cashParticipant"),
db.raw("IFNULL(participationTokenSupply.supply,0) as participationTokenSupply"),
"disavowed",
])
.from("all_participants");
participantQuery.join("fee_windows", "all_participants.feeWindow", "fee_windows.feeWindow");
participantQuery.leftJoin("balances_detail as feeToken", function() {
this.on("feeToken.owner", db.raw("all_participants.participantAddress")).andOn("feeToken.symbol", db.raw("?", "FeeToken"));
});
participantQuery.leftJoin("balances AS cashFeeWindow", function() {
this.on("cashFeeWindow.owner", db.raw("feeToken.feeWindow")).on("cashFeeWindow.token", db.raw("?", getCashAddress(augur)));
});
participantQuery.leftJoin("balances AS cashParticipant", function() {
this.on("cashParticipant.owner", db.raw("participantAddress")).andOn("cashParticipant.token", db.raw("?", getCashAddress(augur)));
});
participantQuery.leftJoin("token_supply as participationTokenSupply", "participationTokenSupply.token", "feeToken.feeWindow");
participantQuery.where("all_participants.universe", universe);
participantQuery.where("all_participants.reporter", reporter);
participantQuery.whereNot("all_participants.participantSupply", "0");
participantQuery.whereNot("all_participants.reporterBalance", "0");
participantQuery.whereRaw("(reportingState IN (?, ?) OR ((disavowed != 0 or all_participants.needsDisavowal) AND (fee_windows.state = ? OR reportingState = ?)))", [
ReportingState.AWAITING_FINALIZATION,
ReportingState.FINALIZED,
FeeWindowState.PAST,
ReportingState.AWAITING_FORK_MIGRATION,
]);
const participantEthFeeRows: Array<ParticipantEthFeeRow> = await participantQuery;
const participantEthFeesOnWindow = _.map(
participantEthFeeRows,
(ethFeeRows): ParticipantEthFee => {
const totalFeeTokensInFeeWindow = new BigNumber(ethFeeRows.feeTokenSupply).plus(new BigNumber(ethFeeRows.participationTokenSupply));
const participantShareOfFeeWindow = totalFeeTokensInFeeWindow.isZero() ? ZERO : new BigNumber(ethFeeRows.feeTokenBalance).dividedBy(totalFeeTokensInFeeWindow);
const cashInFeeWindow = new BigNumber(ethFeeRows.cashFeeWindow);
const participantEthFees = participantShareOfFeeWindow.times(cashInFeeWindow);
const reporterShareOfParticipant = new BigNumber(ethFeeRows.reporterBalance).dividedBy(ethFeeRows.participantSupply);
const ethFees = reporterShareOfParticipant.times(participantEthFees);
return {
participantAddress: ethFeeRows.participantAddress,
feeWindow: ethFeeRows.feeWindow,
ethFees,
fork: ethFeeRows.forking,
};
},
);
// keyBy/valuesIn reduces down to a single object per participantAddress
const cashBalanceByParticipant: Array<ParticipantEthFeeRow> = _.valuesIn(_.keyBy(participantEthFeeRows, "participantAddress"));
const participantEthFeesOnParticipant: Array<ParticipantEthFee> = _.map(cashBalanceByParticipant, (ethFeeRows) => {
const reporterShareOfParticipant = new BigNumber(ethFeeRows.reporterBalance).dividedBy(ethFeeRows.participantSupply);
const participantEthFees = new BigNumber(ethFeeRows.cashParticipant);
const ethFees = reporterShareOfParticipant.times(participantEthFees);
return {
participantAddress: ethFeeRows.participantAddress,
feeWindow: null,
ethFees,
fork: ethFeeRows.forking,
};
});
return participantEthFeesOnWindow.concat(participantEthFeesOnParticipant);
}