Guest User

Untitled

a guest
May 16th, 2018
120
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.78 KB | None | 0 0
  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. }
Add Comment
Please, Sign In to add comment