<commit_before>// Copyright 2016, University of Colorado Boulder

/**
 *
 * @author <NAME> (PhET Interactive Simulations)
 * @author <NAME> (PhET Interactive Simulations)
 */
define( function( require ) {
  'use strict';

  // modules
  var assertInstanceOf = require( 'ifphetio!PHET_IO/assertions/assertInstanceOf' );
  var phetioInherit = require( 'ifphetio!PHET_IO/phetioInherit' );
  var axon = require( 'AXON/axon' );
  var TObject = require( 'ifphetio!PHET_IO/types/TObject' );
  var phetioEvents = require( 'ifphetio!PHET_IO/phetioEvents' );
  var TVoid = require( 'ifphetio!PHET_IO/types/TVoid' );
  var TFunctionWrapper = require( 'ifphetio!PHET_IO/types/TFunctionWrapper' );

  /**
   * Wrapper type for Emitter
   * Emitter for 0, 1 or 2 args, or maybe 3.
   * @param {function[]} phetioArgumentTypes - If loaded by phet (not phet-io), the array will be of functions
   *                                          returned by the 'ifphetio!' plugin.
   * @returns {TEmitterImpl}
   * @constructor
   */
  function TEmitter( phetioArgumentTypes ) {

    var TEmitterImpl = function TEmitterImpl( emitter, phetioID ) {
      assert && assert( phetioArgumentTypes, 'phetioArgumentTypes should be defined' );

      TObject.call( this, emitter, phetioID );
      assertInstanceOf( emitter, phet.axon.Emitter );

      var messageIndex = null;

      // Allow certain Emitters to suppress their data output, such as the frameCompletedEmitter
      if ( emitter.phetioEmitData ) {
        emitter.callbacksStartedEmitter.addListener( function() {
          assert && assert( arguments.length === phetioArgumentTypes.length, 'Wrong number of arguments, expected ' + phetioArgumentTypes.length + ', received ' + arguments.length );
          var p = [];
          for ( var i = 0; i < arguments.length; i++ ) {
            var a = arguments[ i ];
            p.push( a );
          }
          var parameters = { arguments: p };
          messageIndex = phetioEvents.start( 'model', phetioID, TEmitter( phetioArgumentTypes ), 'emitted', parameters );
        } );

        emitter.callbacksEndedEmitter.addListener( function() {
          assert && assert( arguments.length === 0, 'Wrong number of arguments, expected ' + phetioArgumentTypes.length + ', received ' + arguments.length );
          messageIndex && phetioEvents.end( messageIndex );
        } );
      }
    };

    return phetioInherit( TObject, 'TEmitter', TEmitterImpl, {
      addListener: {
        returnType: TVoid,
        parameterTypes: [ TFunctionWrapper( TVoid, phetioArgumentTypes ) ],
        implementation: function( listener ) {
          this.instance.addListener( listener );
        },
        documentation: 'Add a listener which will be called when the emitter emits.'
      }
    }, {
      documentation: 'Emitters indicate when events have occurred, with optional arguments describing the event',
      events: [ 'emitted' ]
    } );
  }

  axon.register( 'TEmitter', TEmitter );

  return TEmitter;
} );

<commit_msg>Cleaned up TEmitter, see https://github.com/phetsims/phet-io/issues/1196<commit_after>// Copyright 2016, University of Colorado Boulder

/**
 *
 * @author <NAME> (PhET Interactive Simulations)
 * @author <NAME> (PhET Interactive Simulations)
 */
define( function( require ) {
  'use strict';

  // modules
  var assertInstanceOf = require( 'ifphetio!PHET_IO/assertions/assertInstanceOf' );
  var phetioInherit = require( 'ifphetio!PHET_IO/phetioInherit' );
  var axon = require( 'AXON/axon' );
  var TObject = require( 'ifphetio!PHET_IO/types/TObject' );
  var phetioEvents = require( 'ifphetio!PHET_IO/phetioEvents' );
  var TVoid = require( 'ifphetio!PHET_IO/types/TVoid' );
  var TFunctionWrapper = require( 'ifphetio!PHET_IO/types/TFunctionWrapper' );

  /**
   * Wrapper type for Emitter
   * Emitter for 0, 1 or 2 args, or maybe 3.
   * @param {function[]} phetioArgumentTypes - If loaded by phet (not phet-io), the array will be of functions
   *                                          returned by the 'ifphetio!' plugin.
   * @returns {TEmitterImpl}
   * @constructor
   */
  function TEmitter( phetioArgumentTypes ) {

    var TEmitterImpl = function TEmitterImpl( emitter, phetioID ) {
      assert && assert( phetioArgumentTypes, 'phetioArgumentTypes should be defined' );

      TObject.call( this, emitter, phetioID );
      assertInstanceOf( emitter, phet.axon.Emitter );

      // Allow certain Emitters to suppress their data output, such as the frameCompletedEmitter
      if ( emitter.phetioEmitData ) {
        emitter.callbacksStartedEmitter.addListener( function() {
          assert && assert( arguments.length === phetioArgumentTypes.length, 'Wrong number of arguments, expected ' + phetioArgumentTypes.length + ', received ' + arguments.length );
          var parameters = { arguments: Array.prototype.slice.call( arguments ) };
          var messageIndex = phetioEvents.start( 'model', phetioID, TEmitter( phetioArgumentTypes ), 'emitted', parameters );

          emitter.callbacksEndedEmitter.addListener( function listener() {
            assert && assert( arguments.length === 0, 'Wrong number of arguments, expected ' + phetioArgumentTypes.length + ', received ' + arguments.length );
            emitter.callbacksEndedEmitter.removeListener( listener );
            phetioEvents.end( messageIndex );
          } );
        } );
      }
    };

    return phetioInherit( TObject, 'TEmitter', TEmitterImpl, {
      addListener: {
        returnType: TVoid,
        parameterTypes: [ TFunctionWrapper( TVoid, phetioArgumentTypes ) ],
        implementation: function( listener ) {
          this.instance.addListener( listener );
        },
        documentation: 'Add a listener which will be called when the emitter emits.'
      }
    }, {
      documentation: 'Emitters indicate when events have occurred, with optional arguments describing the event',
      events: [ 'emitted' ]
    } );
  }

  axon.register( 'TEmitter', TEmitter );

  return TEmitter;
} );


{'fraction_non_alphanumeric': 0.11072261072261072, 'fraction_numerical': 0.0038295038295038295, 'mean_word_length': 3.0261394101876675, 'pattern_counts': {'":': 0, '<': 8, '<?xml version=': 0, '>': 7, 'https://': 1, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 4, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4842482', 'n_tokens_mistral': 1822, 'n_tokens_neox': 1753, 'n_words': 460}