<commit_before>/* jshint esnext: true */
'use strict';

import Map from "carbide/map";
import View from "./view";
import $ from "anon/dom";

import * as QString from "query-string";
function Client(){
  this.$view = new View(document);
  var queryString = location.search;
  var query = QString.parse(queryString);

  var state = Map({
    menu: Map({
      open: location.pathname == "/menu",
    }),
    accelerometer: Map({
      reading: Map({
        x: 0,
        y: 0,
        z: 0
      }),
    }),
    theme: query.theme || "APPLE"
  });
  Object.defineProperty(this, "menuOpen", {
    get: function(){
      return state.menu.open;
    }
  });
  Object.defineProperty(this, "theme", {
    get: function(){
      return state.theme;
    }
  });

  this.location = new Location(this);

  this.openMenu = function(){
    if (state.menu.open) { return; }
    state = state.update("menu", function(map){ return map.set("open", true); });
    this.location.update();
    this.$view.isSpiritLevelMinimised = this.menuOpen;
  };
  this.closeMenu = function(){
    if (!state.menu.open) { return; }
    state = state.update("menu", function(map){ return map.set("open", false); });
    this.location.update();
    // DEBT should call update on an actor
    this.$view.isSpiritLevelMinimised = this.menuOpen;
  };
  this.selectTheme = function(theme){
    // TODO raise error for unknown theme;
    if (state.theme === theme) { return; }

    state = state.set("theme", theme);
    this.location.update();
    this.$view.theme = state.theme;
  };
  // Setup step that should be called when initializing a presenter
  this.$view.theme = state.theme;
}

function Location(projection){
  function url(projection){
    var path = "/";
    if (projection.menuOpen) {
      path = path + "menu";
    }

    var query = {theme: projection.theme.toLowerCase()};
    var queryString = QString.stringify(query);

    return path + "?" + queryString;
  }
<commit_msg>separate state functionality<commit_after>/* jshint esnext: true */
'use strict';

import Map from "carbide/map";
import View from "./view";
import $ from "anon/dom";

import * as QString from "query-string";
var State = {
  create: function(location){
    var queryString = location.search;
    var query = QString.parse(queryString);

    var state = Map({
      menu: Map({
        open: location.pathname == "/menu",
      }),
      accelerometer: Map({
        reading: Map({
          x: 0,
          y: 0,
          z: 0
        }),
      }),
      theme: query.theme || "APPLE"
    });

    return state;
  },
  openMenu: function(state){
    return state.update("menu", function(map){ return map.set("open", true); });
  },
  closeMenu: function(state){
    return state.update("menu", function(map){ return map.set("open", false); });
  }
};

function Client(){
  this.$view = new View(document);
  var state = State.create(window.location);
  Object.defineProperty(this, "menuOpen", {
    get: function(){
      return state.menu.open;
    }
  });
  Object.defineProperty(this, "theme", {
    get: function(){
      return state.theme;
    }
  });

  this.location = new Location(this);

  this.openMenu = function(){
    if (state.menu.open) { return; }
    state = State.openMenu(state);
    this.location.update();
    this.$view.isSpiritLevelMinimised = this.menuOpen;
  };
  this.closeMenu = function(){
    if (!state.menu.open) { return; }
    state = State.closeMenu(state);
    this.location.update();
    // DEBT should call update on an actor
    this.$view.isSpiritLevelMinimised = this.menuOpen;
  };
  this.selectTheme = function(theme){
    // TODO raise error for unknown theme;
    if (state.theme === theme) { return; }

    state = state.set("theme", theme);
    this.location.update();
    this.$view.theme = state.theme;
  };
  // Setup step that should be called when initializing a presenter
  this.$view.theme = state.theme;
}

function Location(projection){
  function url(projection){
    var path = "/";
    if (projection.menuOpen) {
      path = path + "menu";
    }

    var query = {theme: projection.theme.toLowerCase()};
    var queryString = QString.stringify(query);

    return path + "?" + queryString;
  }

{'fraction_non_alphanumeric': 0.15578247447162194, 'fraction_numerical': 0.0014248397055331276, 'mean_word_length': 2.874885004599816, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1402305', 'n_tokens_mistral': 1320, 'n_tokens_neox': 1304, 'n_words': 329}