<commit_before>// See licence.txt for Google BSD license
// Copyright 2011 Google, Inc. <EMAIL>

/*
 * Purple: parse, re-run, breakpoint, loop environment.
 * Parts connector
 */ 
 
 window.purple = window.purple || {};
 
(function purpleFrameworkEnclosure() {
 
  var thePurple = window.purple;
  var Assembly = thePurple.Assembly;
  
  //-------------------------------------------------------------------------
  // Reporting functions that can later be optioned-off 
  thePurple.error = function() {
    console.error.apply(console, arguments);
  };
  thePurple.warn = function() {
    console.warn.apply(console, arguments);
  };
  thePurple.log = function() {
    console.log.apply(console, arguments);
  };
 
  // Parts implement these functions
  // If any method returns a truthy value, the remainder are not notified.
  thePurple.PurplePart = function PurplePart() {};
  thePurple.PurplePart.prototype = {
    // 1. allocate internal data structures
    initialize: function() { },
    // 2. add listeners to other Parts
    connect: function(thePurple) { },
    // end-1. remove listeners from other Parts
    disconnect: function(thePurple) { },
    // end: deallocate internals
    destroy: function() { },
    // ------------------------------------------
    // 3. respond to UI events
    onUserAction: function(action) { },
    // 4. respond to devtools events
    onDevToolEvent: function(event) { },
  };

  Assembly.addPartContainer(thePurple);  
  
  thePurple.preInitialize = [];   // system-level init
  thePurple.postDestroy = [];
  
  thePurple.initialize = function() {
    thePurple.preInitialize.forEach(function callEm(fnc) {
      fnc.apply(null, [thePurple]);
    });
    thePurple.someParts('initialize', [thePurple]);
    thePurple.someParts('connect', [thePurple]);
  };
  
  thePurple.destroy = function() {
    thePurple.someParts('disconnect', [thePurple]);
    thePurple.someParts('destroy', [thePurple]);
    thePurple.postDestroy.forEach(function callEm(fnc) {
      fnc.apply(null, [thePurple]);
    });
  };
  
  function gcLoad() {
    thePurple.initialize();
    window.removeEventListener('load', gcLoad, false);
  }
  window.addEventListener('load', gcLoad, false);

  function gcUnLoad() {
    thePurple.destroy();
    window.removeEventListener('unload', gcLoad, false);
  }
  window.addEventListener('unload', gcUnLoad, false);
  
}());<commit_msg>dispatch init/connect/disconnect/destroy events as forEach not some<commit_after>// See licence.txt for Google BSD license
// Copyright 2011 Google, Inc. <EMAIL>

/*
 * Purple: parse, re-run, breakpoint, loop environment.
 * Parts connector
 */ 
 
 window.purple = window.purple || {};
 
(function purpleFrameworkEnclosure() {
 
  var thePurple = window.purple;
  var Assembly = thePurple.Assembly;
  
  //-------------------------------------------------------------------------
  // Reporting functions that can later be optioned-off 
  thePurple.error = function() {
    console.error.apply(console, arguments);
  };
  thePurple.warn = function() {
    console.warn.apply(console, arguments);
  };
  thePurple.log = function() {
    console.log.apply(console, arguments);
  };
 
  // Parts implement these functions
  // If any method returns a truthy value, the remainder are not notified.
  thePurple.PurplePart = function PurplePart() {};
  thePurple.PurplePart.prototype = {
    // 1. allocate internal data structures
    initialize: function() { },
    // 2. add listeners to other Parts
    connect: function(thePurple) { },
    // end-1. remove listeners from other Parts
    disconnect: function(thePurple) { },
    // end: deallocate internals
    destroy: function() { },
    // ------------------------------------------
    // 3. Respond to new Features
    featureImplemented: function(feature) {},
    featureUnimplemented: function(feature) {},
  };

  Assembly.addPartContainer(thePurple);  
  
  thePurple.preInitialize = [];   // system-level init
  thePurple.postDestroy = [];
  
  thePurple.initialize = function() {
    thePurple.preInitialize.forEach(function callEm(fnc) {
      fnc.apply(null, [thePurple]);
    });
    thePurple.forEachPart('initialize', [thePurple]);
    thePurple.forEachPart('connect', [thePurple]);
  };
  
  thePurple.destroy = function() {
    thePurple.forEachPart('disconnect', [thePurple]);
    thePurple.forEachPart('destroy', [thePurple]);
    thePurple.postDestroy.forEach(function callEm(fnc) {
      fnc.apply(null, [thePurple]);
    });
  };
  
  function gcLoad() {
    thePurple.initialize();
    window.removeEventListener('load', gcLoad, false);
  }
  window.addEventListener('load', gcLoad, false);

  function gcUnLoad() {
    thePurple.destroy();
    window.removeEventListener('unload', gcLoad, false);
  }
  window.addEventListener('unload', gcUnLoad, false);
  
}());
{'fraction_non_alphanumeric': 0.17745604963805583, 'fraction_numerical': 0.003516028955532575, 'mean_word_length': 2.816890292028414, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 5, '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': '3765129', 'n_tokens_mistral': 1519, 'n_tokens_neox': 1406, 'n_words': 309}