Remove circular imports from types (#492)
* Remove circular imports from types - These are creating issues on RN and is not correct - Uint is equivalent to BN (extends it), so remove it. - Don't import all classes (it imports types itself) - CodecTypes can be exposed elsewhere if needed * Cleanup linting & imports * Cleanup compact decoding
This commit is contained in:
@@ -0,0 +1,7 @@
|
||||
// Copyright 2017-2018 @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.
|
||||
|
||||
import * as Classes from './index';
|
||||
|
||||
export type CodecTypes = keyof typeof Classes;
|
||||
@@ -3,7 +3,7 @@
|
||||
// of the Apache-2.0 license. See the LICENSE file for details.
|
||||
|
||||
import BN from 'bn.js';
|
||||
import { bnToBn, compactAddLength, compactFromU8a, compactStripLength, compactToU8a, hexToBn, isBn, isHex, isNumber, isString, isU8a } from '@polkadot/util';
|
||||
import { bnToBn, compactAddLength, compactFromU8a, compactStripLength, compactToU8a, hexToBn, isBn, isHex, isNumber, isString } from '@polkadot/util';
|
||||
import { DEFAULT_BITLENGTH } from '@polkadot/util/compact/defaults';
|
||||
|
||||
import { AnyNumber, Codec, Constructor } from '../types';
|
||||
@@ -56,13 +56,11 @@ export default class Compact extends Base<UInt | Moment> implements Codec {
|
||||
);
|
||||
} else if (isNumber(value) || isBn(value)) {
|
||||
return new Type(bnToBn(value));
|
||||
} else if (isU8a(value)) {
|
||||
const [, _value] = Compact.decodeU8a(value, new Type(0).bitLength());
|
||||
|
||||
return new Type(_value);
|
||||
}
|
||||
|
||||
return new Type(value.toBn());
|
||||
const [, _value] = Compact.decodeU8a(value, new Type(0).bitLength());
|
||||
|
||||
return new Type(_value);
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -3,11 +3,8 @@
|
||||
// of the Apache-2.0 license. See the LICENSE file for details.
|
||||
|
||||
import BN from 'bn.js';
|
||||
import * as Classes from './index';
|
||||
|
||||
import { UInt } from './codec';
|
||||
|
||||
export type AnyNumber = UInt | BN | Uint8Array | number | string;
|
||||
export type AnyNumber = BN | Uint8Array | number | string;
|
||||
|
||||
export type AnyString = string | String;
|
||||
|
||||
@@ -51,8 +48,6 @@ export interface Codec {
|
||||
|
||||
export type CodecTo = 'toHex' | 'toJSON' | 'toString' | 'toU8a';
|
||||
|
||||
export type CodecTypes = keyof typeof Classes;
|
||||
|
||||
export type Constructor<T = Codec> = { new(value?: any): T };
|
||||
|
||||
export type ConstructorDef<T = Codec> = { [index: string]: Constructor<T> };
|
||||
|
||||
Reference in New Issue
Block a user