Figma clientStorage and Svelte store sync

How would one go about synchronizing the Figma clientStorage and a Svelte store? I would like to update the svelte store on plugin launch to match the data in the clientStorage. And then before closing the plugin I would like to save all the svelte store data onto the clientStorage again
Any suggestions or examples of plugins that do that?

I don’t have examples of plugins doing that but here is what I would do:

  1. For the initial retrieval:
    1. On the svelte app load, send an event to the figma backend asking for the figma clientstorage
    2. Return the figmaclient storage to the front
    3. store it in your svelte store
  2. For the saving before closing
    1. After every update of your store on svelte, you should update the figma store therefore when the user close the plugin it’s already saved
    2. Or, you can listen to the event close and do your saving before closing but it’s not recommended on | Plugin API
1 Like