Issie logo Issie

JsonHelpers Module

Types

Type Description

JSONCanvasState

SavedCanvasUnknownWaveInfo<'T>

A saved sheet with its wave info left UNREAD: 'T is instantiated at obj, which parses anything. This is the last resort of jsonStringToState, and it is what lets the saved selection change shape without a legacy reader - a selection this version cannot understand costs the selection, never the sheet. Every variant that can carry wave info is mirrored, because any of them can be the one that fails. Only the newest was, which meant an older save holding an unreadable selection failed to load at all rather than losing it.

SavedInfo

Functions and values

Function or value Description

convStateToJC (compL, connL)

Full Usage: convStateToJC (compL, connL)

Parameters:
Returns: JSONCanvasState

converts a live CanvasState to its file form: legacy-compatible component types, and every integer id written as a decimal string.

compL : Component list
connL : Connection list
Returns: JSONCanvasState

extraCoder

Full Usage: extraCoder

Returns: ExtraCoders
Returns: ExtraCoders

jsonStringToState jsonString

Full Usage: jsonStringToState jsonString

Parameters:
    jsonString : string

Returns: Result<SavedInfo, string>

NB tryParseNativeAs, not tryParseAs. Both are SimpleJson and both end in the same AST-to-value conversion; they differ only in how the AST is built. tryParseAs uses Fable.Parsimmon parser combinators over the whole file and measured ~8x slower than the native JSON.parse variant - 59ms against 7ms on a 108KB sheet - and this function tries up to three types in turn, so it paid that cost more than once per sheet loaded. The two were checked to agree on every demo sheet, for each of the three types below.

jsonString : string
Returns: Result<SavedInfo, string>

stateToJsonString (arg1, arg2, arg3)

Full Usage: stateToJsonString (arg1, arg2, arg3)

Parameters:
Returns: Result<string, string>

The ordinary save: stamped with the time it is written, which is what says which sheet the user was last working on - see MenuHelpers.chooseWhichToOpen. A rewrite that is not an edit of the user's, such as the id conversion a project open does, keeps the stamp it read and goes through stateToJsonStringAt instead.

arg0 : CanvasState
arg1 : SavedWaveInfo option
arg2 : SheetInfo option
Returns: Result<string, string>

stateToJsonStringAt time (cState, waveInfo, sheetInfo)

Full Usage: stateToJsonStringAt time (cState, waveInfo, sheetInfo)

Parameters:
Returns: Result<string, string>

Code to convert a CanvasState to a JSON string, does not work for bigints (I think). A serialisation failure is an Error: it must never be written to the sheet's .dgm file, which would overwrite the sheet with garbage.

time : DateTime
cState : CanvasState
waveInfo : SavedWaveInfo option
sheetInfo : SheetInfo option
Returns: Result<string, string>

stateToJsonStringExperimental (cState, waveInfo, sheetInfo)

Full Usage: stateToJsonStringExperimental (cState, waveInfo, sheetInfo)

Parameters:
Returns: Result<string, string>

Code to convert a CanvasState to a JSON string, allowing bigints

cState : CanvasState
waveInfo : SavedWaveInfo option
sheetInfo : SheetInfo option
Returns: Result<string, string>

Type something to start searching.