Skip to content

Live Json parsing

Compare
Choose a tag to compare
@razshare razshare released this 24 Jan 00:20
· 157 commits to main since this release

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 above previousParsedValue, which is the previous (valid) value of the store.

Full Changelog: 0.5.3...0.6.0