<commit_before>// @flow

import makeRecord from "../utils/makeRecord";
import { List } from "immutable";
import { createSelector } from "reselect";
import { prefs } from "../utils/prefs";

import type { Expression } from "../types";
import type { Action } from "../actions/types";
import type { Record } from "../utils/makeRecord";

type ExpressionState = {
  expressions: List<Expression>
};

export const State = makeRecord(
  ({
    expressions: List(restoreExpressions())
  }: ExpressionState)
);

function update(
  state: Record<ExpressionState> = State(),
  action: Action
): Record<ExpressionState> {
  switch (action.type) {
    case "ADD_EXPRESSION":
      return appendToList(state, ["expressions"], {
        input: action.input,
        value: null,
        updating: true
      });
    case "UPDATE_EXPRESSION":
      const key = action.expression.input;
      return updateItemInList(state, ["expressions"], key, {
        input: action.input,
        value: null,
        updating: true
      });
    case "EVALUATE_EXPRESSION":
      if (action.status === "done") {
        return updateItemInList(state, ["expressions"], action.input, {
          input: action.input,
          value: action.value,
          updating: false
        });
      }
      break;
    case "DELETE_EXPRESSION":
      return deleteExpression(state, action.input);
  }

  return state;
}

function restoreExpressions() {
  const exprs = prefs.expressions;
  if (exprs.length == 0) {
    return;
  }
  return exprs;
}

function storeExpressions(state) {
  prefs.expressions = state.getIn(["expressions"]).toJS();
}
<commit_msg>Omit value (#3759)<commit_after>// @flow

import makeRecord from "../utils/makeRecord";
import { List } from "immutable";
import { omit } from "lodash";
import { createSelector } from "reselect";
import { prefs } from "../utils/prefs";

import type { Expression } from "../types";
import type { Action } from "../actions/types";
import type { Record } from "../utils/makeRecord";

type ExpressionState = {
  expressions: List<Expression>
};

export const State = makeRecord(
  ({
    expressions: List(restoreExpressions())
  }: ExpressionState)
);

function update(
  state: Record<ExpressionState> = State(),
  action: Action
): Record<ExpressionState> {
  switch (action.type) {
    case "ADD_EXPRESSION":
      return appendToList(state, ["expressions"], {
        input: action.input,
        value: null,
        updating: true
      });
    case "UPDATE_EXPRESSION":
      const key = action.expression.input;
      return updateItemInList(state, ["expressions"], key, {
        input: action.input,
        value: null,
        updating: true
      });
    case "EVALUATE_EXPRESSION":
      if (action.status === "done") {
        return updateItemInList(state, ["expressions"], action.input, {
          input: action.input,
          value: action.value,
          updating: false
        });
      }
      break;
    case "DELETE_EXPRESSION":
      return deleteExpression(state, action.input);
  }

  return state;
}

function restoreExpressions() {
  const exprs = prefs.expressions;
  if (exprs.length == 0) {
    return;
  }
  return exprs;
}

function storeExpressions(state) {
  const expressions = state
    .getIn(["expressions"])
    .map(expression => omit(expression, "value"))
    .toJS();

  prefs.expressions = expressions;
}

{'fraction_non_alphanumeric': 0.13649851632047477, 'fraction_numerical': 0.0017804154302670622, 'mean_word_length': 2.998813760379597, 'pattern_counts': {'":': 8, '<': 9, '<?xml version=': 0, '>': 10, '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': '4010826', 'n_tokens_mistral': 1001, 'n_tokens_neox': 998, 'n_words': 250}