<commit_before>/* jshint node:true */

/**
 * FastDom Helper
 *
 * Bakes FastDom API into modules
 * and ensures outstanding jobs
 * are cleaned up when the
 * module is destroyed.
 *
 * @author  Wilson
 * @codingstandard ftlabs-jsv2
 * @copyright The Financial Times Limited [All rights reserved]
 */

'use strict';

/**
 * Module Dependencies
 */

var fastdom = require('fastdom');

/**
 * Exports
 */

module.exports = function(view) {
  var jobs = {
    read: [],
    write: [],
    defer: []
  };

  /**
   * Wraps the fastdom.read
   * API.
   *
   * Keeps track of the job
   * and then removes the
   * refernece when the job
   * is run.
   *
   * @param  {Function} fn
   * @param  {Object}   ctx
   * @api public
   */
  view.read = function(fn, ctx) {
    var job = fastdom.read(function() {
      remove(job, jobs.read);
      fn.call(ctx);
    });

    jobs.read.push(job);
  };

  /**<commit_msg>Protect against the helper being attached to the view multiple times<commit_after>/* jshint node:true */

/**
 * FastDom Helper
 *
 * Bakes FastDom API into modules
 * and ensures outstanding jobs
 * are cleaned up when the
 * module is destroyed.
 *
 * @author  Wilson
 * @codingstandard ftlabs-jsv2
 * @copyright The Financial Times Limited [All rights reserved]
 */

'use strict';

/**
 * Module Dependencies
 */

var fastdom = require('fastdom');

/**
 * Exports
 */

module.exports = function(view) {

  // Protect against the helper being attached to the view multiple times
  if (view.defer) return;

  var jobs = {
    read: [],
    write: [],
    defer: []
  };

  /**
   * Wraps the fastdom.read
   * API.
   *
   * Keeps track of the job
   * and then removes the
   * refernece when the job
   * is run.
   *
   * @param  {Function} fn
   * @param  {Object}   ctx
   * @api public
   */
  view.read = function(fn, ctx) {
    var job = fastdom.read(function() {
      remove(job, jobs.read);
      fn.call(ctx);
    });

    jobs.read.push(job);
  };

  /**
{'fraction_non_alphanumeric': 0.13542193026781202, 'fraction_numerical': 0.001010611419909045, 'mean_word_length': 2.4554973821989527, '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': '5139809', 'n_tokens_mistral': 673, 'n_tokens_neox': 655, 'n_words': 196}