Alternative lazy Submittable (#1370)
* Aletrnative lazy Submittable * Extrinsic -> submittable * .default
This commit is contained in:
+1
-8
@@ -17,8 +17,6 @@ import { filterEvents, isKeyringPair } from '../util';
|
||||
import ApiBase from '../base';
|
||||
import SubmittableResult from './Result';
|
||||
|
||||
type Creator<ApiType> = (extrinsic: Call | Uint8Array | string) => SubmittableExtrinsic<ApiType>;
|
||||
|
||||
interface SubmittableOptions<ApiType> {
|
||||
api: ApiInterfaceRx;
|
||||
decorateMethod: ApiBase<ApiType>['decorateMethod'];
|
||||
@@ -34,7 +32,7 @@ const DEFAULT_MORTAL_LENGTH = 5 * ONE_MINUTE;
|
||||
|
||||
const _Extrinsic: Constructor<Extrinsic> = ClassOf('Extrinsic');
|
||||
|
||||
class Submittable<ApiType> extends _Extrinsic implements SubmittableExtrinsic<ApiType> {
|
||||
export default class Submittable<ApiType> extends _Extrinsic implements SubmittableExtrinsic<ApiType> {
|
||||
private readonly _api: ApiInterfaceRx;
|
||||
|
||||
private readonly _decorateMethod: ApiBase<ApiType>['decorateMethod'];
|
||||
@@ -254,8 +252,3 @@ class Submittable<ApiType> extends _Extrinsic implements SubmittableExtrinsic<Ap
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
export default function createSubmittableExtrinsic<ApiType> (type: ApiTypes, api: ApiInterfaceRx, decorateMethod: ApiBase<ApiType>['decorateMethod']): Creator<ApiType> {
|
||||
return (extrinsic: Call | Uint8Array | string): SubmittableExtrinsic<ApiType> =>
|
||||
new Submittable(extrinsic, { api, decorateMethod, type });
|
||||
}
|
||||
@@ -0,0 +1,27 @@
|
||||
/* eslint-disable no-dupe-class-members */
|
||||
// Copyright 2017-2019 @polkadot/api 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 { Call } from '@polkadot/types/interfaces';
|
||||
import { Constructor } from '@polkadot/types/types';
|
||||
import { ApiInterfaceRx, ApiTypes } from '../types';
|
||||
import { SubmittableExtrinsic } from './types';
|
||||
|
||||
import ApiBase from '../base';
|
||||
|
||||
type Creator<ApiType> = (extrinsic: Call | Uint8Array | string) => SubmittableExtrinsic<ApiType>;
|
||||
|
||||
let Submittable: Constructor<SubmittableExtrinsic<any>>;
|
||||
|
||||
export default function createSubmittable<ApiType> (type: ApiTypes, api: ApiInterfaceRx, decorateMethod: ApiBase<ApiType>['decorateMethod']): Creator<ApiType> {
|
||||
return (extrinsic: Call | Uint8Array | string): SubmittableExtrinsic<ApiType> => {
|
||||
// HACK This is not great, but basically what we do here is to lazily only require the class
|
||||
// right at the point it is actually needed - delaying initialization
|
||||
if (!Submittable) {
|
||||
Submittable = require('./Submittable').default;
|
||||
}
|
||||
|
||||
return new Submittable(extrinsic, { api, decorateMethod, type });
|
||||
};
|
||||
}
|
||||
@@ -2,5 +2,5 @@
|
||||
// This software may be modified and distributed under the terms
|
||||
// of the Apache-2.0 license. See the LICENSE file for details.
|
||||
|
||||
export { default as createSubmittable } from './Extrinsic';
|
||||
export { default as createSubmittable } from './createSubmittable';
|
||||
export { default as SubmittableResult } from './Result';
|
||||
|
||||
Reference in New Issue
Block a user