Introduce bundle exports (#3742)

* Introduce bundle exports

* Move memo

* Cleanup imports

* Move DoNotConstruct
This commit is contained in:
Jaco
2021-07-07 11:35:30 +02:00
committed by GitHub
parent 33ee38dc7a
commit 81be70e15b
41 changed files with 874 additions and 792 deletions
+1 -2
View File
@@ -1,9 +1,8 @@
// Copyright 2017-2021 @polkadot/api-derive authors & contributors
// SPDX-License-Identifier: Apache-2.0
export { drr } from '@polkadot/rpc-core/util';
export { drr, memo } from '@polkadot/rpc-core';
export * from './approvalFlagsToBools';
export * from './cache';
export * from './cacheImpl';
export * from './memo';
-33
View File
@@ -1,33 +0,0 @@
// Copyright 2017-2021 @polkadot/api-derive authors & contributors
// SPDX-License-Identifier: Apache-2.0
import type { Observer, TeardownLogic } from 'rxjs';
import type { Memoized } from '@polkadot/util/types';
import { Observable } from 'rxjs';
import { drr } from '@polkadot/rpc-core/util';
import { memoize } from '@polkadot/util';
type ObsFn <T> = (...params: any[]) => Observable<T>;
// Wraps a derive, doing 2 things to optimize calls -
// 1. creates a memo of the inner fn -> Observable, removing when unsubscribed
// 2. wraps the observable in a drr() (which includes an unsub delay)
/** @internal */
export function memo <T> (instanceId: string, inner: ObsFn<T>): Memoized<ObsFn<T>> {
const cached = memoize(
(...params: any[]): Observable<T> =>
new Observable((observer: Observer<T>): TeardownLogic => {
const subscription = inner(...params).subscribe(observer);
return (): void => {
cached.unmemoize(...params);
subscription.unsubscribe();
};
}).pipe(drr()),
{ getInstanceId: () => instanceId }
);
return cached;
}