Support bare flag on enums (#2518)

* Support bare flag on enums

* Remove extra var allocation
This commit is contained in:
Jaco Greeff
2020-08-25 23:50:30 +02:00
committed by GitHub
parent 5a17c542a7
commit fe951c2645
2 changed files with 3 additions and 3 deletions
+2
View File
@@ -149,6 +149,8 @@ describe('Enum', (): void => {
expect(new Test(registry).toJSON()).toEqual({ A: null });
expect(new Test(registry, 1234, 1).toJSON()).toEqual({ B: 1234 });
expect(new Test(registry, 0x1234, 1).toU8a()).toEqual(new Uint8Array([1, 0x34, 0x12, 0x00, 0x00]));
expect(new Test(registry, 0x1234, 1).toU8a(true)).toEqual(new Uint8Array([0x34, 0x12, 0x00, 0x00]));
});
it('allows accessing the type and value', (): void => {
+1 -3
View File
@@ -338,10 +338,8 @@ export default class Enum implements Codec {
* @param isBare true when the value has none of the type-specific prefixes (internal)
*/
public toU8a (isBare?: boolean): Uint8Array {
const index = this.#indexes[this.#index];
return u8aConcat(
new Uint8Array([index]),
new Uint8Array(isBare ? [] : [this.#indexes[this.#index]]),
this.#raw.toU8a(isBare)
);
}