daily pastebin goal
11%
SHARE
TWEET

Untitled

a guest May 16th, 2018 82 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. const FIXTURE_KEY = "fixtures";
  2.  
  3. /**
  4.  * Turns on fixtures, if they should be turned on. Adds a function
  5.  * to the window object in the browser that makes it easy to toggle
  6.  * fixtures.
  7.  */
  8. export default function() {
  9.   if (process.env.NODE_ENV !== "production") {
  10.     const useFixtures = areFixturesOn();
  11.     setFixtures(useFixtures);
  12.     setFixtureToggle(useFixtures);
  13.   }
  14. }
  15.  
  16. function areFixturesOn() {
  17.   const useFixtures = window.localStorage.getItem(FIXTURE_KEY);
  18.   return useFixtures === null || useFixtures === "true";
  19. }
  20.  
  21. function setFixtureToggle(useFixtures) {
  22.   window.toggleFixtures = () => {
  23.     window.localStorage.setItem(FIXTURE_KEY, (!useFixtures).toString());
  24.     window.location.reload();
  25.   };
  26. }
  27.  
  28. function setFixtures(useFixtures) {
  29.   if (useFixtures) {
  30.     require("./fixtures");
  31.   }
  32. }
RAW Paste Data
Top