Refactor serialization
This commit is contained in:
parent
8e44dd3733
commit
b3da27e73b
1 changed files with 142 additions and 133 deletions
13
shared/src/transport/serialization/deserialize.ts
Normal file
13
shared/src/transport/serialization/deserialize.ts
Normal file
|
|
@ -0,0 +1,13 @@
|
|||
import { serializableMapping } from './serializable-mapping';
|
||||
|
||||
export const deserialize = (json: string): any => {
|
||||
return JSON.parse(json, (k, v) => {
|
||||
const possibleType = v[0];
|
||||
const overridableConstructor = serializableMapping.get(possibleType);
|
||||
if (overridableConstructor) {
|
||||
v.shift();
|
||||
return new overridableConstructor.constructor(...v);
|
||||
}
|
||||
return v;
|
||||
});
|
||||
};
|
||||
Loading…
Reference in a new issue