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:
+1
-1
@@ -9,7 +9,7 @@ Tuples now return single types when only one type is available, i.e. `(AccountId
|
||||
Api Promise has been updated in the way we deal with subscriptions. Previously a subscription returned `Promise<number>` where the caller was to keep track of the id and use it in subsequent unsubscribes. Now any subscriptions return an unsubscribe/destroy function `(): void`, that is use for removing the subscriptions, e.g.
|
||||
|
||||
```js
|
||||
const unsubscribe = api.query.balance.freeBalanceOf(Alice, (balance) => {...});
|
||||
const unsubscribe = api.query.balance.freeBalance(Alice, (balance) => {...});
|
||||
|
||||
unsubscribe(); // here we destroy the subscription
|
||||
```
|
||||
|
||||
@@ -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