Live Json parsing
Changes
-
You can now parse messages to json as they come in.
You can also recover from errors while parsing and/or buffering while parsing.<script> import { source } from 'sveltekit-sse' const connection = source('/custom-event') const json = connection1.select('message').json( function onJsonParseError({error, currentRawValue, previousParsedValue}){ console.error(`Could not parse "${currentRawValue}" as json.`, error) return previousParsedValue // this will be the new value of the store } ) $: console.log({$json}) </svelte>
When an parsing error occurs,
onJsonParseError
is invoked.
Whatever this function returns will become the new value of the store, in the example abovepreviousParsedValue
, which is the previous (valid) value of the store.
Full Changelog: 0.5.3...0.6.0