<commit_before>import { range } from "lodash/fp";
import {
  getDiscoveryProjects,
  getDiscoverySamples,
  getDiscoveryVisualizations,
} from "./discovery_api";

class ObjectCollection {
  constructor(domain, apiFunction) {
    this.domain = domain;
    this.entries = {};
    this.apiFunction = apiFunction;
  }

  createView = viewProps => {
    return new ObjectCollectionView(this, viewProps);
  };
}

class ObjectCollectionView {
  constructor(collection, { conditions = {}, onViewChange = null }) {
    this._orderedIds = null;
    this._loading = true;
    this._collection = collection;
    this._conditions = conditions;
    this._activePromises = {};

    this._onViewChange = onViewChange;
  }

  get loaded() {
    return (this._orderedIds || [])
      .filter(id => id in this._collection.entries)
      .map(id => this._collection.entries[id]);
  }
  get length() {
    return (this._orderedIds || []).length;
  }
  get = id => this._collection.entries[id];
  getIds = () => this._orderedIds || [];
  getCollectionLength = () => {
    return Object.keys(this._collection.entries).length;
  };
  isLoading = () => this._loading;
  update = entry => {
    this._collection.entries[entry.id] = entry;
  };
  reset = ({ conditions } = {}) => {
    this._orderedIds = null;
    this._loading = true;
    this._conditions = conditions;
    this._activePromises = {};<commit_msg>[Bug fix] Fix bug when updating project after changes to membership. (#2589)<commit_after>import { range } from "lodash/fp";
import {
  getDiscoveryProjects,
  getDiscoverySamples,
  getDiscoveryVisualizations,
} from "./discovery_api";

class ObjectCollection {
  constructor(domain, apiFunction) {
    this.domain = domain;
    this.entries = {};
    this.apiFunction = apiFunction;
  }

  createView = viewProps => {
    return new ObjectCollectionView(this, viewProps);
  };

  update = entry => {
    this.entries[entry.id] = entry;
  };
}

class ObjectCollectionView {
  constructor(collection, { conditions = {}, onViewChange = null }) {
    this._orderedIds = null;
    this._loading = true;
    this._collection = collection;
    this._conditions = conditions;
    this._activePromises = {};

    this._onViewChange = onViewChange;
  }

  get loaded() {
    return (this._orderedIds || [])
      .filter(id => id in this._collection.entries)
      .map(id => this._collection.entries[id]);
  }
  get length() {
    return (this._orderedIds || []).length;
  }
  get = id => this._collection.entries[id];
  getIds = () => this._orderedIds || [];
  getCollectionLength = () => {
    return Object.keys(this._collection.entries).length;
  };
  isLoading = () => this._loading;
  reset = ({ conditions } = {}) => {
    this._orderedIds = null;
    this._loading = true;
    this._conditions = conditions;
    this._activePromises = {};
{'fraction_non_alphanumeric': 0.14331210191082802, 'fraction_numerical': 0.0014154281670205238, 'mean_word_length': 3.3559322033898304, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 21, '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': '3139018', 'n_tokens_mistral': 857, 'n_tokens_neox': 839, 'n_words': 171}