<commit_before>var Reflux = require('reflux');
var _ = require('lodash');

var deviceActions = require('actions/device');
var devicesService = require('services/devices/devices-service');
var discoveryStore = require('stores/discovery-store');

var deviceStore = Reflux.createStore({
  init: function init () {
    this.listenTo(discoveryStore, this.onDiscoveryUpdate);
    this.listenTo(deviceActions.fetchList, this.onFetchList);

    var devices = [
      {
        id: '0',
        name: 'yetu Home Gateway',
        type: 'Home Gateway',
        state: 'connected',
        description: 'test description'
      },
      {
        id: '1',
        name: 'Nest',
        type: 'Thermostat',
        state: 'not conn.',
        description: 'test description'
      },
      {
        id: '2',
        name: 'Nest',
        type: 'Thermostat',
        state: 'connected',
        description: 'test description'
      }
    ];

    this.deviceList = {
      devices: devices,
      deviceById: _.indexBy(devices, 'id'),
      error: null
    };
    this.onFetchList();
  },

  getInitialState: function getInitialState () {
    return this.deviceList;
  },

  onDiscoveryUpdate: function onDisoveryUpdate () {
    this.onFetchList();
  },

  onFetchList: function onFetchList () {
    var self = this;
    devicesService.fetchDeviceList()
      .subscribe(self.updateModel.bind(self),
      self.updateError.bind(self));
  },

  updateModel: function updateModel (devices) {
    this.deviceList = {
      devices: devices,
      deviceById: _.indexBy(devices, 'id'),
      error: null
    };
    this.trigger(this.deviceList);
  },

  updateError: function updateError (error) {
    this.deviceList = {
      error: error
    };
    this.trigger(this.deviceList);
  }
});

module.exports = deviceStore;
<commit_msg>Extract a model creation method<commit_after>var Reflux = require('reflux');
var _ = require('lodash');

var deviceActions = require('actions/device');
var devicesService = require('services/devices/devices-service');
var discoveryStore = require('stores/discovery-store');

var deviceStore = Reflux.createStore({
  init: function init () {
    this.listenTo(discoveryStore, this.onDiscoveryUpdate);
    this.listenTo(deviceActions.fetchList, this.onFetchList);

    var devices = [
      {
        id: '0',
        name: 'yet<NAME>',
        type: 'Home Gateway',
        state: 'connected',
        description: 'test description'
      },
      {
        id: '1',
        name: 'Nest',
        type: 'Thermostat',
        state: 'not conn.',
        description: 'test description'
      },
      {
        id: '2',
        name: 'Nest',
        type: 'Thermostat',
        state: 'connected',
        description: 'test description'
      }
    ];

    this.deviceList = this.createModel(devices);
    this.onFetchList();
  },

  createModel: function createModel (devices) {
    return {
      devices: devices,
      deviceById: _.indexBy(devices, 'id'),
      error: null
    };
  },

  getInitialState: function getInitialState () {
    return this.deviceList;
  },

  onDiscoveryUpdate: function onDisoveryUpdate () {
    this.onFetchList();
  },

  onFetchList: function onFetchList () {
    var self = this;
    devicesService.fetchDeviceList()
      .subscribe(self.updateModel.bind(self),
      self.updateError.bind(self));
  },

  updateModel: function updateModel (devices) {
    this.deviceList = this.createModel(devices);
    this.trigger(this.deviceList);
  },

  updateError: function updateError (error) {
    this.deviceList = {
      error: error
    };
    this.trigger(this.deviceList);
  }
});

module.exports = deviceStore;

{'fraction_non_alphanumeric': 0.1329700272479564, 'fraction_numerical': 0.0016348773841961854, 'mean_word_length': 2.6968781470292043, 'pattern_counts': {'":': 0, '<': 4, '<?xml version=': 0, '>': 4, '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': '3865092', 'n_tokens_mistral': 1115, 'n_tokens_neox': 1080, 'n_words': 228}