diff --git a/src/index.ts b/src/index.ts index 58a4898..ab3fb26 100644 --- a/src/index.ts +++ b/src/index.ts @@ -10,7 +10,7 @@ export interface Ser { serializeFloat32: (n: number) => void serializeString: (str: string) => void serializeArray: (arr: T[], serialize: (ser: Ser, t: T) => void) => void - serializeIterable (iterable: Iterable, serialize: (ser: Ser, t: T) => void): void + serializeIterable: (iterable: Iterable, serialize: (ser: Ser, t: T) => void) => void } export interface Des { index: number @@ -23,7 +23,7 @@ export interface Des { deserializeFloat32: () => number deserializeString: () => string deserializeArray: (deserialize: (des: Des) => T) => T[] - deserializeIterable (deserialize: (des: Des) => T): Iterable + deserializeIterable: (deserialize: (des: Des) => T) => Iterable } export function createSer (): Ser { @@ -63,7 +63,7 @@ export function createDes (buffer: ArrayBuffer): Des { deserializeFloat32, deserializeString, deserializeArray, - deserializeIterable, + deserializeIterable } } @@ -131,16 +131,15 @@ function serializeIterable (this: Ser, iterable: Iterable, serialize: (ser function deserializeIterable (this: Des, deserialize: (des: Des) => T): Iterable { const len = this.deserializeUInt32() - const des = this - const aGeneratorObject = (function* () { + const aGeneratorObject = (function * (des) { for (let i = 0; i < len; i++) { yield deserialize(des) } - })(); + })(this) return { - [Symbol.iterator]() { - return aGeneratorObject; - }, + [Symbol.iterator] () { + return aGeneratorObject + } } }