diff --git a/CHANGELOG.md b/CHANGELOG.md index 1891d660ec..2a6f4ec912 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,16 +2,21 @@ ## master +Contributed: + +- Bump `@substrate/connect` to 0.7.7 (Thanks to https://github.com/wirednkod) + Changes: - Align `BeefyPayload` with Substrate master +- Use `static get [Symbol.species] ()` for `Array` & `Uint8Array` types ## 8.9.1 Jun 19, 2022 Contributed: -- Update `@substrate/connect` to latest (Thanks to https://github.com/tomaka) +- Update `@substrate/connect` to 0.7.6 (Thanks to https://github.com/tomaka) Changes: diff --git a/packages/types-codec/src/abstract/Array.ts b/packages/types-codec/src/abstract/Array.ts index dd92d1bb95..e6a6e2027a 100644 --- a/packages/types-codec/src/abstract/Array.ts +++ b/packages/types-codec/src/abstract/Array.ts @@ -20,6 +20,14 @@ export abstract class AbstractArray extends Array implements public createdAtHash?: IU8a; + /** + * @description This ensures that operators such as clice, filter, map, etc. return + * new Array instances (without this we need to apply overrides) + */ + static get [Symbol.species] (): typeof Array { + return Array; + } + protected constructor (registry: Registry, length: number) { super(length); @@ -169,43 +177,4 @@ export abstract class AbstractArray extends Array implements return encoded; } - - // Below are methods that we override. When we do a `new Vec(...).map()`, - // we want it to return an Array. We only override the methods that return a - // new instance. - - /** - * @description Concatenates two arrays - */ - public override concat (other: T[]): T[] { - return this.toArray().concat(other instanceof AbstractArray ? other.toArray() : other); - } - - /** - * @description Filters the array with the callback - */ - public override filter (callbackfn: (value: T, index: number, array: T[]) => boolean, thisArg?: unknown): T[] { - return this.toArray().filter(callbackfn, thisArg); - } - - /** - * @description Maps the array with the callback - */ - public override map (callbackfn: (value: T, index: number, array: T[]) => U, thisArg?: unknown): U[] { - return this.toArray().map(callbackfn, thisArg); - } - - /** - * @description Checks if the array includes a specific value - */ - public override includes (check: unknown): boolean { - return this.some((value: T) => value.eq(check)); - } - - /** - * @description Returns a slice of an array - */ - public override slice (start?: number, end?: number): T[] { - return this.toArray().slice(start, end); - } } diff --git a/packages/types-codec/src/native/Raw.ts b/packages/types-codec/src/native/Raw.ts index b231867217..7948d4d27e 100644 --- a/packages/types-codec/src/native/Raw.ts +++ b/packages/types-codec/src/native/Raw.ts @@ -22,6 +22,14 @@ export class Raw extends Uint8Array implements IU8a { public readonly registry: Registry; + /** + * @description This ensures that operators such as clice, filter, map, etc. return + * new Array instances (without this we need to apply overrides) + */ + static get [Symbol.species] (): typeof Uint8Array { + return Uint8Array; + } + constructor (registry: Registry, value?: AnyU8a, initialU8aLength?: number) { super(u8aToU8a(value)); @@ -64,14 +72,6 @@ export class Raw extends Uint8Array implements IU8a { return isUtf8(this); } - /** - * @description The length of the value - */ - public override get length (): number { - // only included here since we ignore inherited docs - return super.length; - } - /** * @description Returns the number of bits in the value */ @@ -100,26 +100,6 @@ export class Raw extends Uint8Array implements IU8a { }; } - /** - * @description Create a new slice from the actual buffer. (compat) - * @param start The position to start at - * @param end The position to end at - */ - public override slice (start?: number, end?: number): Uint8Array { - // Like subarray below, we have to follow this approach since we are extending the TypeArray. - // This happens especially when it comes to further extensions, the length may be an override - return Uint8Array.from(this).slice(start, end); - } - - /** - * @description Create a new subarray from the actual buffer. (compat) - * @param begin The position to start at - * @param end The position to end at - */ - public override subarray (begin?: number, end?: number): Uint8Array { - return Uint8Array.from(this).subarray(begin, end); - } - /** * @description Returns a hex string representation of the value */