diff --git a/packages/api-derive/src/index.spec.ts b/packages/api-derive/src/index.spec.ts index ed1df43b74..28c58f76c0 100644 --- a/packages/api-derive/src/index.spec.ts +++ b/packages/api-derive/src/index.spec.ts @@ -22,13 +22,6 @@ const testFunction = (api: ApiInterface$Rx) => { it('should return an Observable', () => { expect((api.derive[section][method] as any)(...inputs)).toBeInstanceOf(Observable); }); - - it('should be memoized', () => { - const first = (api.derive[section][method] as any)(...inputs); - const second = (api.derive[section][method] as any)(...inputs); - - expect(first).toBe(second); - }); }); }; }; diff --git a/packages/api-derive/src/index.ts b/packages/api-derive/src/index.ts index 824c818da3..df464424e1 100644 --- a/packages/api-derive/src/index.ts +++ b/packages/api-derive/src/index.ts @@ -5,7 +5,6 @@ import { Observable } from 'rxjs'; import { ApiInterface$Rx } from '@polkadot/api/types'; -import { cache } from './util/cache'; import * as accounts from './accounts'; import * as balances from './balances'; import * as chain from './chain'; @@ -49,13 +48,8 @@ function injectFunctions (api: ApiInterface$Rx, derive: Derive, functions: Deriv const result = derive[sectionName as keyof Derive] = derive[sectionName as keyof Derive] || {}; Object.keys(section).forEach((methodName) => { - // Create cache for the section_method function // @ts-ignore No idea how to make this work... - const cached = cache(section[methodName as keyof section]); - - // Add this cached function into the result - // @ts-ignore No idea how to make this work... - result[methodName as keyof section] = cached(api); + result[methodName as keyof section] = section[methodName as keyof section](api); }); }); diff --git a/packages/api-derive/src/util/cache.spec.ts b/packages/api-derive/src/util/cache.spec.ts deleted file mode 100644 index 8c64ff4682..0000000000 --- a/packages/api-derive/src/util/cache.spec.ts +++ /dev/null @@ -1,30 +0,0 @@ -// Copyright 2017-2019 @polkadot/api-derive authors & contributors -// This software may be modified and distributed under the terms -// of the Apache-2.0 license. See the LICENSE file for details. - -import { ApiInterface$Rx } from '@polkadot/api/types'; - -import { cache } from './cache'; - -describe('cache', () => { - 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); - const second = f(api)(2, 3); - - expect(first).toBe(second); - }); - - it('should not hit cache when some arguments are not the same', () => { - const first = f(api)(2, 3); - const second1 = f(api)(5, 3); - const second2 = f(api)(2, 5); - const second3 = f({} as ApiInterface$Rx)(2, 3); - - expect(first).not.toBe(second1); - expect(first).not.toBe(second2); - expect(first).not.toBe(second3); - }); -}); diff --git a/packages/api-derive/src/util/cache.ts b/packages/api-derive/src/util/cache.ts deleted file mode 100644 index 0f647985ee..0000000000 --- a/packages/api-derive/src/util/cache.ts +++ /dev/null @@ -1,31 +0,0 @@ -// Copyright 2017-2019 @polkadot/api-derive authors & contributors -// This software may be modified and distributed under the terms -// of the Apache-2.0 license. See the LICENSE file for details. - -import memoizee from 'memoizee'; -import { ApiInterface$Decorated } from '@polkadot/api/types'; -import { Codec } from '@polkadot/types/types'; -import { Observable } from 'rxjs'; -/** - * Create memoization for a 2-currified function. - * - * @param fn - The function to memoize. - * @param map - The Map used to cache function returns. - * @example - * ```javascript - * const f = (api: ApiInterface$Rx) => (b: number) => a * b; - * const cached = cache(f); - * f(api)(1, 2); - * f(api)(1); // Cache not hit - * f({})(1, 2); // Cache not hit - * f(api)(1, 2); // Cache hit - * ``` - */ -export const cache = (fn: Function, map = new WeakMap()) => (api: ApiInterface$Decorated, Observable>) => { - if (!map.has(api)) { - const innerFn = fn(api); - map.set(api, memoizee(innerFn)); - } - - return map.get(api); -}; diff --git a/packages/api-derive/test/e2e/promise.spec.ts b/packages/api-derive/test/e2e/promise.spec.ts new file mode 100644 index 0000000000..9c5a8d0485 --- /dev/null +++ b/packages/api-derive/test/e2e/promise.spec.ts @@ -0,0 +1,32 @@ +// Copyright 2017-2019 @polkadot/api-derive authors & contributors +// This software may be modified and distributed under the terms +// of the Apache-2.0 license. See the LICENSE file for details. + +import ApiPromise from '@polkadot/api/promise/Api'; +import { BlockNumber } from '@polkadot/types'; +import { WsProvider } from '@polkadot/rpc-provider'; + +const WS_LOCAL = 'ws://127.0.0.1:9944/'; +// const WS_POC3 = 'wss://poc3-rpc.polkadot.io/'; + +describe.skip('derive e2e', () => { + let api: ApiPromise; + + beforeAll(() => { + jest.setTimeout(30000); + }); + + beforeEach(async (done) => { + api = await ApiPromise.create(new WsProvider(WS_LOCAL)); + done(); + }); + + it('returns correct results', async () => { + // https://github.com/polkadot-js/api/issues/777 + const block1 = await api.derive.chain.bestNumber(); + await new Promise((resolve) => setTimeout(resolve, 15000)); + const block2 = await api.derive.chain.bestNumber(); + + expect((block1 as BlockNumber).eq(block2)).toBe(false); + }); +}); diff --git a/packages/api-derive/test/e2e/derive.spec.ts b/packages/api-derive/test/e2e/rx.spec.ts similarity index 97% rename from packages/api-derive/test/e2e/derive.spec.ts rename to packages/api-derive/test/e2e/rx.spec.ts index 38bb6ac9b3..a725957449 100644 --- a/packages/api-derive/test/e2e/derive.spec.ts +++ b/packages/api-derive/test/e2e/rx.spec.ts @@ -1,4 +1,4 @@ -// Copyright 2017-2018 @polkadot/api-derive authors & contributors +// Copyright 2017-2019 @polkadot/api-derive authors & contributors // This software may be modified and distributed under the terms // of the Apache-2.0 license. See the LICENSE file for details. diff --git a/packages/types/src/type/NonceCompact.ts b/packages/types/src/type/NonceCompact.ts index 0e9fd4d591..8c841fefb8 100644 --- a/packages/types/src/type/NonceCompact.ts +++ b/packages/types/src/type/NonceCompact.ts @@ -1,4 +1,4 @@ -// Copyright 2017-2018 @polkadot/types authors & contributors +// Copyright 2017-2019 @polkadot/types authors & contributors // This software may be modified and distributed under the terms // of the Apache-2.0 license. See the LICENSE file for details.