<commit_before>import Em from 'ember';

var get = Em.get,
    getMeta = Em.getMeta,
    setMeta = Em.setMeta;

var defaultFilter = function(value) { console.log('value', value); return value; };

export default function(dependentKey, filter) {
  filter = filter || defaultFilter;

  return Em.computed(function(key) {
    var hasObserverKey = '_changeGate:%@:hasObserver'.fmt(key);
    var lastValueKey =   '_changeGate:%@:lastValue'.fmt(key);
    var isFirstRun = !getMeta(this, hasObserverKey);

    if(isFirstRun) { //setup an observer which is responsible for notifying property changes
      var value = filter(get(this, dependentKey));

      setMeta(this, hasObserverKey, true);
      setMeta(this, lastValueKey, value);

      this.addObserver(dependentKey, function() {
        var newValue = filter(get(this, dependentKey));
        var lastValue = getMeta(this, lastValueKey);

        if(newValue !== lastValue) {
          setMeta(this, lastValueKey, newValue);
          this.notifyPropertyChange(key);
        }
      });

      return value;
    } else {
      return getMeta(this, lastValueKey);
    }
  });
}<commit_msg>Refactored macro to use ComputedProperty meta instead of object's meta - Includes fix to problem caused by not saving meta<commit_after>import Em from 'ember';

var get = Em.get;

var defaultFilter = function(value) { console.log('value', value); return value; };

export default function(dependentKey, filter) {
  filter = filter || defaultFilter;

  var computed = Em.computed(function handler(key) {
    var meta = computed.meta();
    var isFirstRun = !meta.hasObserver;

    var result;
    if(isFirstRun) { //setup an observer which is responsible for notifying property changes
      var value = filter(get(this, dependentKey));

      meta.hasObserver = true;
      meta.lastValue = value;

      this.addObserver(dependentKey, function() {
        var meta = computed.meta();
        var newValue = filter(get(this, dependentKey));
        var lastValue = meta.lastValue;

        if(newValue !== lastValue) {
          meta.lastValue = newValue;
          computed.meta(meta);
          this.notifyPropertyChange(key);
        }
      });

      result = value;
    } else {
      result = meta.lastValue;
    }
    computed.meta(meta);
    return result;
  });

  return computed;
}
{'fraction_non_alphanumeric': 0.11497211497211497, 'fraction_numerical': 0.0, 'mean_word_length': 3.0912280701754384, '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': '2929806', 'n_tokens_mistral': 675, 'n_tokens_neox': 661, 'n_words': 178}