Swap order of combinator inputs, fn + args (as in storage) (#537)
* Swap order of combinator inputs, fn + args (as in storage) * Update api exposed combination * Update CHANGELOG usage (small doc fix)
This commit is contained in:
@@ -20,12 +20,12 @@ export default class Combinator {
|
||||
protected _results: Array<any> = [];
|
||||
protected _unsubscriptions: Array<UnsubFunction | any> = [];
|
||||
|
||||
constructor (fns: Array<CombinatorFunction | [Array<any>, CombinatorFunction]>, callback: CombinatorCallback) {
|
||||
constructor (fns: Array<CombinatorFunction | [CombinatorFunction, ...Array<any>]>, callback: CombinatorCallback) {
|
||||
this._callback = callback;
|
||||
this._unsubscriptions = fns.map((input, index) => {
|
||||
const [args, fn] = Array.isArray(input)
|
||||
const [fn, ...args] = Array.isArray(input)
|
||||
? input
|
||||
: [[], input];
|
||||
: [input];
|
||||
|
||||
this._fired.push(false);
|
||||
this._fns.push(fn);
|
||||
|
||||
@@ -237,15 +237,15 @@ export default class ApiPromise extends ApiBase<DecoratedRpc, QueryableStorage,
|
||||
*
|
||||
* // combines values from balance & nonce as it updates
|
||||
* api.combineLatest([
|
||||
* (cb) => api.rpc.chain.subscribeNewHead(cb),
|
||||
* (cb) => api.query.balances.freeBalance(address, cb),
|
||||
* api.rpc.chain.subscribeNewHead,
|
||||
* [api.query.balances.freeBalance, address],
|
||||
* (cb) => api.query.system.accountNonce(address, cb)
|
||||
* ], ([head, balance, nonce]) => {
|
||||
* console.log(`#${head.number}: You have ${balance} units, with ${nonce} transactions sent`);
|
||||
* });
|
||||
* ```
|
||||
*/
|
||||
combineLatest (fns: Array<CombinatorFunction | [Array<any>, CombinatorFunction]>, callback: CombinatorCallback): UnsubFunction {
|
||||
combineLatest (fns: Array<CombinatorFunction | [CombinatorFunction, ...Array<any>]>, callback: CombinatorCallback): UnsubFunction {
|
||||
const combinator = new Combinator(fns, callback);
|
||||
|
||||
return (): void => {
|
||||
|
||||
Reference in New Issue
Block a user