<commit_before>/* eslint-disable max-statements */
// View for location

var emitter = require('component-emitter');
var ui = require('georap-ui');
var LocationModel = require('./Model');
var NameView = require('./Name');
var ThumbnailView = require('./Thumbnail');
var PlacesView = require('./Places');
var GeomView = require('./Geom');
var StatusTypeView = require('./StatusType');
var FormsView = require('./Forms');
var RemoveView = require('./Remove');
var PostsView = require('./Posts');
var EventsView = require('./Events');
var template = require('./template.ejs');
var locations = georap.stores.locations;
var able = georap.stores.account.able;
var ableOwn = georap.stores.account.ableOwn;
var __ = georap.i18n.__;

var LocationView = function (id, query) {
  // Parameters
  //   id
  //     location id
  //   query
  //     url query parameters from router
  //
  // Emits
  //   idle
  //     with a Location
  //     when view is rendered and bound
  //   removed
  //     when model emits "removed"

  // Init
  var $mount = null;
  var self = this;
  var $elems = {};
  var children = {};
  emitter(self);

  // State
  var _location;

  // Public methods

  self.bind = function ($mountEl) {
    $mount = $mountEl;

    // Loading
    $mount.html(template({
      // ref: Where the location was referred
      ref: query.ref === 'latest' ? 'latest' : 'map',
      __: __,
    }));

    $elems.loading = $mount.find('.location-loading');

    // Fetch location before rendering.
    locations.getOne(id, function (err, rawLoc) {
      ui.hide($elems.loading);

      if (err) {
        if (err.message && err.message.toLowerCase() === 'not found') {
          console.warn('Location ' + id + ' not found');
          ui.show($mount.find('.location-missing-error'));
          return;
        }
        console.log('error.message', err.message);
        console.table(err);
        console.error(err);
        return;
      }

      // Set state
      _location = new LocationModel(rawLoc);

      children.nameView = new NameView(_location);
      children.nameView.bind($mount.find('.location-name'));

      if (able('locations-statustype')) {
        children.statusType = new StatusTypeView(_location);
        children.statusType.bind($mount.find('.location-statustype'));
      }

      if (able('locations-places')) {
        children.placesView = new PlacesView(_location);
        children.placesView.bind($mount.find('.location-places'));
      }
<commit_msg>stabile callback, ensure that loc view is mounted<commit_after>/* eslint-disable max-statements */
// View for location

var emitter = require('component-emitter');
var ui = require('georap-ui');
var LocationModel = require('./Model');
var NameView = require('./Name');
var ThumbnailView = require('./Thumbnail');
var PlacesView = require('./Places');
var GeomView = require('./Geom');
var StatusTypeView = require('./StatusType');
var FormsView = require('./Forms');
var RemoveView = require('./Remove');
var PostsView = require('./Posts');
var EventsView = require('./Events');
var template = require('./template.ejs');
var locations = georap.stores.locations;
var able = georap.stores.account.able;
var ableOwn = georap.stores.account.ableOwn;
var __ = georap.i18n.__;

var LocationView = function (id, query) {
  // Parameters
  //   id
  //     location id
  //   query
  //     url query parameters from router
  //
  // Emits
  //   idle
  //     with a Location
  //     when view is rendered and bound
  //   removed
  //     when model emits "removed"

  // Init
  var $mount = null;
  var self = this;
  var $elems = {};
  var children = {};
  emitter(self);

  // State
  var _location;

  // Public methods

  self.bind = function ($mountEl) {
    $mount = $mountEl;

    // Loading
    $mount.html(template({
      // ref: Where the location was referred
      ref: query.ref === 'latest' ? 'latest' : 'map',
      __: __,
    }));

    $elems.loading = $mount.find('.location-loading');

    // Fetch location before rendering.
    locations.getOne(id, function (err, rawLoc) {
      // Ensure that component is bound.
      // When user navigates quickly from location to another
      // then callback might arrive after unbind.
      if (!$mount) {
        return;
      }

      ui.hide($elems.loading);

      if (err) {
        if (err.message && err.message.toLowerCase() === 'not found') {
          console.warn('Location ' + id + ' not found');
          ui.show($mount.find('.location-missing-error'));
          return;
        }
        console.log('error.message', err.message);
        console.table(err);
        console.error(err);
        return;
      }

      // Set state
      _location = new LocationModel(rawLoc);

      children.nameView = new NameView(_location);
      children.nameView.bind($mount.find('.location-name'));

      if (able('locations-statustype')) {
        children.statusType = new StatusTypeView(_location);
        children.statusType.bind($mount.find('.location-statustype'));
      }

      if (able('locations-places')) {
        children.placesView = new PlacesView(_location);
        children.placesView.bind($mount.find('.location-places'));
      }

{'fraction_non_alphanumeric': 0.1548511047070125, 'fraction_numerical': 0.0007684918347742555, 'mean_word_length': 2.6102635228848823, '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': '3292792', 'n_tokens_mistral': 1565, 'n_tokens_neox': 1517, 'n_words': 373}