<commit_before><link rel="import" href="../bower_components/polymer/polymer-element.html">

<dom-module id="boardgame-render-player-info">
  <template>
    <div id="container">
    <!-- This is where renderer will go -->
    </div>
  </template>

  <script>

    class BoardgameRenderPlayerInfo extends Polymer.Element {

      static get is() {
        return "boardgame-render-player-info"
      }

      static get properties() {
        return {
          state: {
            type: Object,
          },
          gameName: {
            type: String,
            observer: "_gameNameChanged"
          },
          renderer: Object,
          rendererGameName: String,
          rendererLoaded: {
            type: Boolean,
            value: false,
            observer: "_rendererLoadedChanged",
          },
          chipText: {
            type: String,
            notify: true,
          },
          chipColor: {
            type: String,
            notify: true,
          },
          playerIndex: Number,
        }
      }

      static get observers() {
        return [
          "_stateChanged(state.*)"
        ]
      }

      ready() {
        super.ready();

        if (this.instantiateWhenReady) {
          this.instantiateRenderer();
        }
      }

      _chipTextChanged(e) {
        this.chipText = e.detail.value;
      }

      _chipColorChanged(e) {
        this.chipColor = e.detail.value;
      }

      _gameNameChanged(newValue) {
        if (!newValue) return;
        if (newValue != this.rendererGameName) {
          this.resetRenderer();
        }
        if (!this.instantiateWhenGameNameSet) return;
        this.instantiateRenderer();
      }

      _rendererLoadedChanged(newValue) {
        if (!newValue) return;
        if (!this.renderer) {
          this.instantiateRenderer();
        }
      }

      _stateChanged(record) {

        if (!this.renderer) return;

        this.renderer.set(record.path, record.value);
        //This shiouldn't be necessary... set should have already done
        //notifyPath. Bug in Polymer 2?
        this.renderer.notifyPath(record.path);

      }

      resetRenderer() {
        if (!this.$ || !this.$.container) return;
        var container = this.$.container;
        container.removeChild(this.renderer);
        this.renderer = null;
        this.rendererGameName = "";
      }

      instantiateRenderer() {

        if (!this.rendererLoaded) return;
        if (!this.$) {
          this.instantiateWhenReady = true;
          return
        }

        if (!this.gameName) {
          this.instantiateWhenGameNameSet = true;
          return;
        }

        var ele = document.createElement("boardgame-render-player-info-" + this.gameName);


        ele.state = this.state;
        ele.playerIndex = this.playerIndex;<commit_msg>Handle a case where calling resetRenderer the first time could fail. Part of #376.<commit_after><link rel="import" href="../bower_components/polymer/polymer-element.html">

<dom-module id="boardgame-render-player-info">
  <template>
    <div id="container">
    <!-- This is where renderer will go -->
    </div>
  </template>

  <script>

    class BoardgameRenderPlayerInfo extends Polymer.Element {

      static get is() {
        return "boardgame-render-player-info"
      }

      static get properties() {
        return {
          state: {
            type: Object,
          },
          gameName: {
            type: String,
            observer: "_gameNameChanged"
          },
          renderer: Object,
          rendererGameName: String,
          rendererLoaded: {
            type: Boolean,
            value: false,
            observer: "_rendererLoadedChanged",
          },
          chipText: {
            type: String,
            notify: true,
          },
          chipColor: {
            type: String,
            notify: true,
          },
          playerIndex: Number,
        }
      }

      static get observers() {
        return [
          "_stateChanged(state.*)"
        ]
      }

      ready() {
        super.ready();

        if (this.instantiateWhenReady) {
          this.instantiateRenderer();
        }
      }

      _chipTextChanged(e) {
        this.chipText = e.detail.value;
      }

      _chipColorChanged(e) {
        this.chipColor = e.detail.value;
      }

      _gameNameChanged(newValue) {
        if (!newValue) return;
        if (newValue != this.rendererGameName) {
          this.resetRenderer();
        }
        if (!this.instantiateWhenGameNameSet) return;
        this.instantiateRenderer();
      }

      _rendererLoadedChanged(newValue) {
        if (!newValue) return;
        if (!this.renderer) {
          this.instantiateRenderer();
        }
      }

      _stateChanged(record) {

        if (!this.renderer) return;

        this.renderer.set(record.path, record.value);
        //This shiouldn't be necessary... set should have already done
        //notifyPath. Bug in Polymer 2?
        this.renderer.notifyPath(record.path);

      }

      resetRenderer() {
        if (!this.$ || !this.$.container) return;
        if (this.renderer) {
          var container = this.$.container;
          container.removeChild(this.renderer);
        }
        this.renderer = null;
        this.rendererGameName = "";
      }

      instantiateRenderer() {

        if (!this.rendererLoaded) return;
        if (!this.$) {
          this.instantiateWhenReady = true;
          return
        }

        if (!this.gameName) {
          this.instantiateWhenGameNameSet = true;
          return;
        }

        var ele = document.createElement("boardgame-render-player-info-" + this.gameName);


        ele.state = this.state;
        ele.playerIndex = this.playerIndex;
{'fraction_non_alphanumeric': 0.11341632088520055, 'fraction_numerical': 0.0008644536652835408, 'mean_word_length': 1.6331360946745561, 'pattern_counts': {'":': 0, '<': 19, '<?xml version=': 0, '>': 19, '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': '1690644', 'n_tokens_mistral': 1627, 'n_tokens_neox': 1570, 'n_words': 316}