<commit_before>'use strict';

const createLifecyclesManager = db => {
  const lifecycleManager = {
    _subscribers: [],
    subscribe(subscriber) {
      // TODO: verify subscriber

      this._subscribers.push(subscriber);

      return () => {
        this._subscribers.splice(this._subscribers.indexOf(subscriber), 1);
      };
    },

    createEvent(action, uid, properties) {
      const model = db.metadata.get(uid);

      return {
        action,
        model,
        ...properties,
      };
    },

    async run(action, uid, properties) {
      for (const subscriber of this._subscribers) {
        if (typeof subscriber === 'function') {
          const event = this.createEvent(action, uid, properties);
          return await subscriber(event);
        }

        const hasAction = action in subscriber;
        const hasModel = !subscriber.models || subscriber.models.includes(uid);

        if (hasAction && hasModel) {
          const event = this.createEvent(action, uid, properties);

          await subscriber[action](event);
        }
      }
    },

    clear() {
      this._subscribers = [];
    },
  };

  return lifecycleManager;
};

module.exports = {
  createLifecyclesManager,
};<commit_msg>Using private prefix only if the property is exposed<commit_after>'use strict';

const createLifecyclesManager = db => {
  let subscribers = [];

  const lifecycleManager = {
    subscribe(subscriber) {
      // TODO: verify subscriber
      subscribers.push(subscriber);

      return () => {
        subscribers.splice(subscribers.indexOf(subscriber), 1);
      };
    },

    createEvent(action, uid, properties) {
      const model = db.metadata.get(uid);

      return {
        action,
        model,
        ...properties,
      };
    },

    async run(action, uid, properties) {
      for (const subscriber of subscribers) {
        if (typeof subscriber === 'function') {
          const event = this.createEvent(action, uid, properties);
          return await subscriber(event);
        }

        const hasAction = action in subscriber;
        const hasModel = !subscriber.models || subscriber.models.includes(uid);

        if (hasAction && hasModel) {
          const event = this.createEvent(action, uid, properties);

          await subscriber[action](event);
        }
      }
    },

    clear() {
      subscribers = [];
    },
  };

  return lifecycleManager;
};

module.exports = {
  createLifecyclesManager,
};
{'fraction_non_alphanumeric': 0.11996746644977634, 'fraction_numerical': 0.0008133387555917039, 'mean_word_length': 2.306451612903226, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 7, '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': '1547015', 'n_tokens_mistral': 713, 'n_tokens_neox': 672, 'n_words': 153}