diff --git a/app/soapbox/containers/soapbox.js b/app/soapbox/containers/soapbox.js index 279cad403..c011d0f0d 100644 --- a/app/soapbox/containers/soapbox.js +++ b/app/soapbox/containers/soapbox.js @@ -25,6 +25,7 @@ import { getSoapboxConfig } from 'soapbox/actions/soapbox'; import { generateThemeCss } from 'soapbox/utils/theme'; import messages from 'soapbox/locales/messages'; import { FE_SUBDIRECTORY } from 'soapbox/build_config'; +import { createGlobals } from 'soapbox/globals'; const validLocale = locale => Object.keys(messages).includes(locale); @@ -33,6 +34,9 @@ const previewVideoState = 'previewVideoModal'; export const store = configureStore(); +// Configure global functions for developers +createGlobals(store); + store.dispatch(preload()); store.dispatch(fetchMe()) diff --git a/app/soapbox/globals.js b/app/soapbox/globals.js new file mode 100644 index 000000000..3b49e1fe6 --- /dev/null +++ b/app/soapbox/globals.js @@ -0,0 +1,20 @@ +/** + * globals: do things through the console. + * This feature is for developers. + */ +import { changeSetting } from 'soapbox/actions/settings'; + +export const createGlobals = store => { + const Soapbox = { + // Become a developer with `Soapbox.isDeveloper()` + isDeveloper: (bool = true) => { + if (![true, false].includes(bool)) { + throw `Invalid option ${bool}. Must be true or false.`; + } + store.dispatch(changeSetting(['isDeveloper'], bool)); + return bool; + }, + }; + + window.Soapbox = Soapbox; +};