ai
This commit is contained in:
parent
b6db7e8dc7
commit
d9b80b92ca
1 changed files with 563 additions and 62 deletions
13
shared/src/serialization/serialized-fields.ts
Normal file
13
shared/src/serialization/serialized-fields.ts
Normal file
|
|
@ -0,0 +1,13 @@
|
|||
// Derive a serializable object's positional wire array from a single declared
|
||||
// list of field names, so toArray() and the constructor share ONE source of
|
||||
// truth for field order instead of a hand-written array that can silently drift
|
||||
// out of step with the parameters.
|
||||
//
|
||||
// deserialize reconstructs via `new Ctor(...array.slice(1))`, so the field list
|
||||
// MUST name the constructor's parameters in order. Fields a constructor
|
||||
// recomputes from others (e.g. a planet's centre/radius from its vertices) are
|
||||
// derived, not serialized, and so are deliberately absent from the list.
|
||||
export const toArrayFromFields = (
|
||||
object: any,
|
||||
fields: ReadonlyArray<string>,
|
||||
): Array<any> => fields.map((field) => object[field]);
|
||||
Loading…
Reference in a new issue