Refactor api-promise/rx (#566)

* Use a generic abstract OnCall

* Add OnCall for Promise

* First run at fixing extrinsics

* Fix types

* Make submittable extrinsic work

* Move file

* Make derive work

* Fix types

* Only call metadata once

* Make tests pass

* Put event emitter in apirx

* Fix small bugs

* Fix tests

* Fix bug decorateStorage

* Make tests pass for tx

* Move rpc base to apirx

* Fix lint

* Fix small bugs

* Fix bug with isSubscription

* Fix codeclimate

* Revert

* Add tslint disable line

* Fix lint

* Skip e2e

* Typo

* Lint

* Re-add combinator back

* Add ._rx in Base

* Make extrinsics work

* Update derivex

* Fix bug lint

* Fix circular dep

* Fix bug e2e

* Remove useless check

* Add description comment

* Clean stuff

* Move assert to Base

* Bump version, update CHANGELOG

* Make _rx private

* Private emit
This commit is contained in:
Amaury Martiny
2019-01-16 15:42:59 +01:00
committed by Jaco Greeff
parent 38d2d06772
commit d07ed8ac38
49 changed files with 523 additions and 617 deletions
+4 -4
View File
@@ -2,13 +2,13 @@
// This software may be modified and distributed under the terms
// of the Apache-2.0 license. See the LICENSE file for details.
import ApiRx from '@polkadot/api/rx';
import { ApiInterface$Rx } from '@polkadot/api/types';
import { cache } from './cache';
describe('cache', () => {
const f = cache((api: ApiRx) => (a: number, b: number) => [api, a, b]);
const api = {} as ApiRx;
const f = cache((api: ApiInterface$Rx) => (a: number, b: number) => [api, a, b]);
const api = {} as ApiInterface$Rx;
it('should hit cache when all arguments are the same', () => {
const first = f(api)(2, 3);
@@ -21,7 +21,7 @@ describe('cache', () => {
const first = f(api)(2, 3);
const second1 = f(api)(5, 3);
const second2 = f(api)(2, 5);
const second3 = f({} as ApiRx)(2, 3);
const second3 = f({} as ApiInterface$Rx)(2, 3);
expect(first).not.toBe(second1);
expect(first).not.toBe(second2);
+3 -3
View File
@@ -3,7 +3,7 @@
// of the Apache-2.0 license. See the LICENSE file for details.
import memoizee from 'memoizee';
import ApiRx from '@polkadot/api/rx';
import { ApiInterface$Rx } from '@polkadot/api/types';
/**
* Create memoization for a 2-currified function.
@@ -12,7 +12,7 @@ import ApiRx from '@polkadot/api/rx';
* @param map - The Map used to cache function returns.
* @example
* ```javascript
* const f = (api: ApiRx) => (b: number) => a * b;
* const f = (api: ApiInterface$Rx) => (b: number) => a * b;
* const cached = cache(f);
* f(api)(1, 2);
* f(api)(1); // Cache not hit
@@ -20,7 +20,7 @@ import ApiRx from '@polkadot/api/rx';
* f(api)(1, 2); // Cache hit
* ```
*/
export const cache = (fn: Function, map = new WeakMap()) => (api: ApiRx) => {
export const cache = (fn: Function, map = new WeakMap()) => (api: ApiInterface$Rx) => {
if (!map.has(api)) {
const innerFn = fn(api);
map.set(api, memoizee(innerFn));