Comparing version 0.12.0 to 0.12.1
@@ -18,3 +18,7 @@ export interface SerializerOptions { | ||
constructor(options: SerializerOptions); | ||
keys: Set<string>; | ||
write(key: string, value: unknown): void; | ||
ids: number; | ||
private getNextID; | ||
push(value: unknown): string; | ||
flush(): void; | ||
@@ -21,0 +25,0 @@ close(): void; |
{ | ||
"name": "seroval", | ||
"type": "module", | ||
"version": "0.12.0", | ||
"version": "0.12.1", | ||
"files": [ | ||
@@ -69,3 +69,3 @@ "dist", | ||
}, | ||
"gitHead": "48c2471aa7c00af0409a9bf7313a6d135055cab6" | ||
"gitHead": "497e434530bf4368ec569fdb617c3549b4df6256" | ||
} |
@@ -26,3 +26,5 @@ import { serializeString } from './string'; | ||
export const GLOBAL_CONTEXT_API_SCRIPT = `self.${GLOBAL_CONTEXT_API}=self.${GLOBAL_CONTEXT_API}||{` | ||
const GLOBAL_CONTEXT_API_REF = `self.${GLOBAL_CONTEXT_API}`; | ||
export const GLOBAL_CONTEXT_API_SCRIPT = `${GLOBAL_CONTEXT_API_REF}=${GLOBAL_CONTEXT_API_REF}||{` | ||
+ `${GLOBAL_CONTEXT_PROMISE_CONSTRUCTOR}:function(s,f,p){return(p=new Promise(function(a,b){s=a,f=b})).${LOCAL_CONTEXT_PROMISE_RESOLVE}=s,p.${LOCAL_CONTEXT_PROMISE_REJECT}=f,p},` | ||
@@ -39,5 +41,5 @@ + `uP:function(p){delete p.${LOCAL_CONTEXT_PROMISE_RESOLVE};delete p.${LOCAL_CONTEXT_PROMISE_REJECT}},` | ||
if (id == null) { | ||
return `self.${GLOBAL_CONTEXT_REFERENCES}=self.${GLOBAL_CONTEXT_REFERENCES}||[];`; | ||
return `${GLOBAL_CONTEXT_API_REF}=${GLOBAL_CONTEXT_API_REF}||[];`; | ||
} | ||
return `(self.${GLOBAL_CONTEXT_REFERENCES}=self.${GLOBAL_CONTEXT_REFERENCES}||{})["${serializeString(id)}"]=[];`; | ||
return `(${GLOBAL_CONTEXT_API_REF}=${GLOBAL_CONTEXT_API_REF}||{})["${serializeString(id)}"]=[];`; | ||
} |
@@ -31,5 +31,8 @@ import { crossSerializeStream } from './cross'; | ||
keys = new Set<string>(); | ||
write(key: string, value: unknown): void { | ||
if (this.alive && !this.flushed) { | ||
this.pending++; | ||
this.keys.add(key); | ||
this.cleanups.push(crossSerializeStream(value, { | ||
@@ -62,2 +65,17 @@ scopeId: this.options.scopeId, | ||
ids = 0; | ||
private getNextID(): string { | ||
while (this.keys.has('' + this.ids)) { | ||
this.ids++; | ||
} | ||
return '' + this.ids; | ||
} | ||
push(value: unknown): string { | ||
const newID = this.getNextID(); | ||
this.write(newID, value); | ||
return newID; | ||
} | ||
flush(): void { | ||
@@ -64,0 +82,0 @@ if (this.alive) { |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
1120998
16026