Skip to content

charton API


charton API / @chart-on/core / index / autosave

Function: autosave() ​

autosave(chart, options): Autosave

Defined in: packages/core/src/storage/autosave.ts:92

Save the chart's layout after changes, debounced. Listens to state:change, so loading a layout, drawings or indicators never saves. Saving needs the layouts() plugin; without it each save fails through onError, and the changes stay for the next save, e.g. after chart.install(layouts()). A save due while a loaded layout's symbol is still loading is dropped: the chart reports the edits made meanwhile once it has loaded, and those save then.

Before loading another layout into the chart, await flush() so pending changes go to the layout they belong to.

Parameters ​

chart ​

Chart

options ​

AutosaveOptions

Returns ​

Autosave

Example ​

ts
const saver = autosave(chart, {
  save: (layout) => storage.saveLayout(layoutEntry(layout, 'Main', 'main')).then(() => {}),
});
await saver.flush(); // before loading another layout