Last active
April 5, 2023 16:45
-
-
Save timohausmann/d08bfbca4f4dc16496f91eeede7c4a79 to your computer and use it in GitHub Desktop.
π£ Extention for theatre.js Studio to clear the local state
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import studio from '@theatre/studio'; | |
import { studioResetExtention } from './studioResetExtention'; | |
// just extend studio | |
studio.extend(studioResetExtention); | |
studio.initialize(); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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