Skip to content

Instantly share code, notes, and snippets.

@timohausmann
Last active April 5, 2023 16:45
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save timohausmann/d08bfbca4f4dc16496f91eeede7c4a79 to your computer and use it in GitHub Desktop.
Save timohausmann/d08bfbca4f4dc16496f91eeede7c4a79 to your computer and use it in GitHub Desktop.
💣 Extention for theatre.js Studio to clear the local state
import studio from '@theatre/studio';
import { studioResetExtention } from './studioResetExtention';
// just extend studio
studio.extend(studioResetExtention);
studio.initialize();
// The code below assumes that your project is set up with TypeScript and a bundler.
// And Nextjs, otherwise you can delete the window checks.
import { IExtension, ToolsetConfig } from '@theatre/studio'
import { resetClientStudio } from './resetClientStudio';
export const studioResetExtention: IExtension = {
id: 'th-reset',
toolbars: {
// @ts-ignore
global(set) {
const toolsetConfig: ToolsetConfig = [{
type: 'Icon',
title: 'Reset Studio',
svgSource: '💣',
onClick: () => {
if(typeof window === 'undefined') return;
if(window.confirm('Warning: this will clear your entire localStorage and reload the Theatre Project State provided to getProject.')) {
localStorage.clear();
window.location.reload();
}
}
}]
set(toolsetConfig);
},
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment