<commit_before>var capitalize = require('lodash/string/capitalize');
var assign = require('object-assign');
var {isObject, isArray} = require('lodash/lang');
var keys = require('lodash/object/keys');
var storeChangeBehaviour = require('./store-change-behaviour');

var storeMixin = {
  mixins: [storeChangeBehaviour],
  /**
   * Get the state informations from the store.
   * @returns {object} - The js object constructed from store data.
   */
  _getStateFromStores: function formGetStateFromStore() {
    if (this.getStateFromStore) {
      return this.getStateFromStore();
    }
    var newState = {};
    this.stores.map((storeConf) => {
      storeConf.properties.map((property)=>{
        newState[property] = storeConf.store[`get${capitalize(property)}`]();
      });
    });
    return assign(this._computeEntityFromStoresData(newState), this._getLoadingStateFromStores());
  },
    /**
     * Get the error state informations from the store.
     * @returns {object} - The js error object constructed from the store data.
     */
  _getErrorStateFromStores: function formGetErrorStateFromStore() {
      if (this.getErrorStateFromStore) {
          return this.getErrorStateFromStore();
      }
      var newState = {};
      this.stores.map((storeConf) => {
          storeConf.properties.map((property)=>{
              newState[property] = storeConf.store[`getError${capitalize(property)}`]();
          });
      });
      return this._computeEntityFromStoresData(newState);
  },
  /**
   * Get the isLoading state from  all the store.
   */
  _getLoadingStateFromStores: function getLoadingStateFromStores(){
    if (this.getLoadingStateFromStores) {
        return this.getLoadingStateFromStores();
    }
    var isLoading = false;
    this.stores.map((storeConf) => {
        if(!isLoading){
          storeConf.properties.map((property)=>{
            if(!isLoading){
              var propStatus = storeConf.store.getStatus(property) || {};
               isLoading = propStatus.isLoading;
            }
          });
        }
    });
    return {isLoading: isLoading};
  },
  /**
   * Compute the data given from the stores.
   * @param {object} data -  The data ordered by store.
   * @returns {object} - The js object transformed from store data.
   */
  _computeEntityFromStoresData: function(data) {
    if(this.computeEntityFromStoresData){
      return this.computeEntityFromStoresData(data);
    }
    var entity = {reference: {}};
    for(var key in data){
      if(this.referenceNames && this.referenceNames.indexOf(key) !== -1 ){
        entity.reference[key] = data[key];
      }else {
        var d = data[key];
        if(isArray(d) || !isObject(d)){
          d = {[key] : d};
        }
        assign(entity, d);
      }
    }
    return entity;
  },
  /**
   * Register all the listeners related to the page.
   */
  _registerListeners: function registerStoreListeners() {
    if (this.stores) {
      this.stores.map((storeConf) => {
        storeConf.properties.map((property)=>{
          if(!storeConf.store || !storeConf.store.definition || !storeConf.store.definition[property]){
            console.warn(`You add a property : ${property} in your store which is not in your definition : ${keys(storeConf.store.definition)}`);
          }
          storeConf.store[`add${capitalize(property)}ChangeListener`](this._onChange);
          storeConf.store[`add${capitalize(property)}ErrorListener`](this._onError);
        });
      });
    }
  },
  /**
  * Unregister all the listeners related to the page.
  */
  _unRegisterListeners: function unregisterListener() {
    if (this.stores) {
      this.stores.map((storeConf) => {
        storeConf.properties.map((property)=>{
          storeConf.store[`remove${capitalize(property)}ChangeListener`](this._onChange);
          storeConf.store[`remove${capitalize(property)}ErrorListener`](this._onError);
        });
      });
    }
  },
  /** @inheritdoc */
  componentWillMount: function storeBehaviourWillMount() {
    //These listeners are registered before the mounting because they are not correlated to the DOM.
    //Build the definitions.
    this._registerListeners();
  },
  /** @inheritdoc */
  componentWillUnmount: function storeBehaviourWillUnmount() {
    this._unRegisterListeners();
  }
};

module.exports = storeMixin;
<commit_msg>[store-behaviour] Read the correct value on the isReady.<commit_after>var capitalize = require('lodash/string/capitalize');
var assign = require('object-assign');
var {isObject, isArray} = require('lodash/lang');
var keys = require('lodash/object/keys');
var storeChangeBehaviour = require('./store-change-behaviour');

var storeMixin = {
  mixins: [storeChangeBehaviour],
  /**
   * Get the state informations from the store.
   * @returns {object} - The js object constructed from store data.
   */
  _getStateFromStores: function formGetStateFromStore() {
    if (this.getStateFromStore) {
      return this.getStateFromStore();
    }
    var newState = {};
    this.stores.map((storeConf) => {
      storeConf.properties.map((property)=>{
        newState[property] = storeConf.store[`get${capitalize(property)}`]();
      });
    });
    let computedState = assign(this._computeEntityFromStoresData(newState), this._getLoadingStateFromStores());
    return computedState;
  },
    /**
     * Get the error state informations from the store.
     * @returns {object} - The js error object constructed from the store data.
     */
  _getErrorStateFromStores: function formGetErrorStateFromStore() {
      if (this.getErrorStateFromStore) {
          return this.getErrorStateFromStore();
      }
      var newState = {};
      this.stores.map((storeConf) => {
          storeConf.properties.map((property)=>{
              newState[property] = storeConf.store[`getError${capitalize(property)}`]();
          });
      });
      return this._computeEntityFromStoresData(newState);
  },
  /**
   * Get the isLoading state from  all the store.
   */
  _getLoadingStateFromStores: function getLoadingStateFromStores(){
    if (this.getLoadingStateFromStores) {
        return this.getLoadingStateFromStores();
    }
    let isLoading = false;
    this.stores.forEach((storeConf) => {
        if(!isLoading){
          storeConf.properties.forEach((property)=>{
            if(!isLoading){
              let propStatus = storeConf.store.getStatus(property) || {};
               isLoading = propStatus.isLoading;
            }
          });
        }
    });
    //console.info('Processing state', this.stores, 'loading', isLoading);
    return {isLoading: isLoading};
  },
  /**
   * Compute the data given from the stores.
   * @param {object} data -  The data ordered by store.
   * @returns {object} - The js object transformed from store data.
   */
  _computeEntityFromStoresData: function(data) {
    if(this.computeEntityFromStoresData){
      return this.computeEntityFromStoresData(data);
    }
    var entity = {reference: {}};
    for(var key in data){
      if(this.referenceNames && this.referenceNames.indexOf(key) !== -1 ){
        entity.reference[key] = data[key];
      }else {
        var d = data[key];
        if(isArray(d) || !isObject(d)){
          d = {[key] : d};
        }
        assign(entity, d);
      }
    }
    return entity;
  },
  /**
   * Register all the listeners related to the page.
   */
  _registerListeners: function registerStoreListeners() {
    if (this.stores) {
      this.stores.map((storeConf) => {
        storeConf.properties.map((property)=>{
          if(!storeConf.store || !storeConf.store.definition || !storeConf.store.definition[property]){
            console.warn(`You add a property : ${property} in your store which is not in your definition : ${keys(storeConf.store.definition)}`);
          }
          storeConf.store[`add${capitalize(property)}ChangeListener`](this._onChange);
          storeConf.store[`add${capitalize(property)}ErrorListener`](this._onError);
        });
      });
    }
  },
  /**
  * Unregister all the listeners related to the page.
  */
  _unRegisterListeners: function unregisterListener() {
    if (this.stores) {
      this.stores.map((storeConf) => {
        storeConf.properties.map((property)=>{
          storeConf.store[`remove${capitalize(property)}ChangeListener`](this._onChange);
          storeConf.store[`remove${capitalize(property)}ErrorListener`](this._onError);
        });
      });
    }
  },
  /** @inheritdoc */
  componentWillMount: function storeBehaviourWillMount() {
    //These listeners are registered before the mounting because they are not correlated to the DOM.
    //Build the definitions.
    this._registerListeners();
  },
  /** @inheritdoc */
  componentWillUnmount: function storeBehaviourWillUnmount() {
    this._unRegisterListeners();
  }
};

module.exports = storeMixin;

{'fraction_non_alphanumeric': 0.13547438652041163, 'fraction_numerical': 0.00022616759018432659, 'mean_word_length': 2.9855790896800363, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 23, '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': '5268527', 'n_tokens_mistral': 2597, 'n_tokens_neox': 2538, 'n_words': 519}