<commit_before><!--
@license
Copyright (c) 2014 The Polymer Project Authors. All rights reserved.
This code may only be used under the BSD style license found at http://polymer.github.io/LICENSE.txt
The complete set of authors may be found at http://polymer.github.io/AUTHORS.txt
The complete set of contributors may be found at http://polymer.github.io/CONTRIBUTORS.txt
Code distributed by Google as part of the polymer project is also
subject to an additional IP rights grant found at http://polymer.github.io/PATENTS.txt
-->
<link rel="import" href="../elements/legacy-element.html">
<link rel="import" href="../utils/utils.html">
<script>

  (function() {

    'use strict';

    var utils = Polymer.Utils;
    var LegacyElementMixin = Polymer.LegacyElementMixin;

    var metaProps = {
      attached: true,
      detached: true,
      ready: true,
      created: true,
      beforeRegister: true,
      registered: true,
      attributeChanged: true,
      // meta objects
      behaviors: true,
      hostAttributes: true,
      properties: true,
      observers: true,
      listeners: true
    }

    var mixinBehaviors = function(behaviors, klass) {
      for (var i=0; i<behaviors.length; i++) {
        var b = behaviors[i];
        if (b) {
          klass = Array.isArray(b) ? mixinBehaviors(b, klass) :
            MixinBehavior(b, klass);
        }
      }
      return klass;
    }

    var flattenBehaviors = function(behaviors, list) {
      list = list || [];
      if (behaviors) {
        for (var i=0; i < behaviors.length; i++) {
          var b = behaviors[i];
          if (b) {
            if (Array.isArray(b)) {
              flattenBehaviors(b, list);
            } else {
              if (list.indexOf(b) < 0) {
                list.push(b);
              }
            }
          } else {
            Polymer._warn('behavior is null, check for missing or 404 import');
          }
        }
      }
      return list;
    }

    var MixinBehavior = function(behavior, Base) {

      var config = {
        properties: behavior.properties,
        observers: behavior.observers,
        generatedFrom: behavior
      };

      class PolymerGenerated extends Base {

        static get config() {
          return config;
        }

        static get template() {
          return behavior._template || super.template;
        }

        _invokeFunction(fn, args) {
          if (fn) {
            fn.apply(this, args);
          }
        }

        constructor() {
          super();
          // call `registered` only if it was not called for *this* constructor
          if (!PolymerGenerated.hasOwnProperty('__registered')) {
            PolymerGenerated.__registered = true;
            if (behavior.registered) {
              behavior.registered.call(Object.getPrototypeOf(this));
            }
          }
        }

        created() {
          super.created();
          this._invokeFunction(behavior.created);
        }

        _applyListeners() {
          super._applyListeners();
          this._applyConfigListeners(behavior);
        }

        _ensureAttributes() {
          // ensure before calling super so that subclasses can override defaults
          this._ensureConfigAttributes(behavior);
          super._ensureAttributes();
        }

        ready() {
          super.ready();
          this._invokeFunction(behavior.ready);
        }
<commit_msg>Move `behavior.registered` to `_initializeProperties` when other initialization work is done. Allow `_template` to be set in a behavior.<commit_after><!--
@license
Copyright (c) 2014 The Polymer Project Authors. All rights reserved.
This code may only be used under the BSD style license found at http://polymer.github.io/LICENSE.txt
The complete set of authors may be found at http://polymer.github.io/AUTHORS.txt
The complete set of contributors may be found at http://polymer.github.io/CONTRIBUTORS.txt
Code distributed by Google as part of the polymer project is also
subject to an additional IP rights grant found at http://polymer.github.io/PATENTS.txt
-->
<link rel="import" href="../elements/legacy-element.html">
<link rel="import" href="../utils/utils.html">
<script>

  (function() {

    'use strict';

    var utils = Polymer.Utils;
    var LegacyElementMixin = Polymer.LegacyElementMixin;

    var metaProps = {
      attached: true,
      detached: true,
      ready: true,
      created: true,
      beforeRegister: true,
      registered: true,
      attributeChanged: true,
      // meta objects
      behaviors: true,
      hostAttributes: true,
      properties: true,
      observers: true,
      listeners: true
    }

    var mixinBehaviors = function(behaviors, klass) {
      for (var i=0; i<behaviors.length; i++) {
        var b = behaviors[i];
        if (b) {
          klass = Array.isArray(b) ? mixinBehaviors(b, klass) :
            MixinBehavior(b, klass);
        }
      }
      return klass;
    }

    var flattenBehaviors = function(behaviors, list) {
      list = list || [];
      if (behaviors) {
        for (var i=0; i < behaviors.length; i++) {
          var b = behaviors[i];
          if (b) {
            if (Array.isArray(b)) {
              flattenBehaviors(b, list);
            } else {
              if (list.indexOf(b) < 0) {
                list.push(b);
              }
            }
          } else {
            Polymer._warn('behavior is null, check for missing or 404 import');
          }
        }
      }
      return list;
    }

    var MixinBehavior = function(behavior, Base) {

      var config = {
        properties: behavior.properties,
        observers: behavior.observers,
        generatedFrom: behavior
      };

      class PolymerGenerated extends Base {

        static get config() {
          return config;
        }

        static get template() {
          return behavior._template || super.template || this.prototype._template;
        }

        _invokeFunction(fn, args) {
          if (fn) {
            fn.apply(this, args);
          }
        }

        _initializeProperties() {
          // call `registered` only if it was not called for *this* constructor
          if (!PolymerGenerated.hasOwnProperty('__registered')) {
            PolymerGenerated.__registered = true;
            if (behavior.registered) {
              behavior.registered.call(Object.getPrototypeOf(this));
            }
          }
          super._initializeProperties();
        }

        created() {
          super.created();
          this._invokeFunction(behavior.created);
        }

        _applyListeners() {
          super._applyListeners();
          this._applyConfigListeners(behavior);
        }

        _ensureAttributes() {
          // ensure before calling super so that subclasses can override defaults
          this._ensureConfigAttributes(behavior);
          super._ensureAttributes();
        }

        ready() {
          super.ready();
          this._invokeFunction(behavior.ready);
        }

{'fraction_non_alphanumeric': 0.10415180482237124, 'fraction_numerical': 0.0028534741047224997, 'mean_word_length': 1.915973377703827, 'pattern_counts': {'":': 0, '<': 17, '<?xml version=': 0, '>': 11, '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': '5793096', 'n_tokens_mistral': 1931, 'n_tokens_neox': 1866, 'n_words': 516}