<commit_before>import Helper from '@ember/component/helper';
import { inject as service } from '@ember/service';
import { addObserver, removeObserver } from '@ember/object/observers';
import { setProperties } from '@ember/object';

export default Helper.extend({
  can: service(),

  ability: null,
  propertyName: null,

  compute([abilityString, model], properties) {
    let { abilityName, propertyName } = this.can.parse(abilityString);
    let ability = this.can.abilityFor(abilityName, model, properties);

    propertyName = ability.parseProperty(propertyName);

    this._removeAbilityObserver();
    this._addAbilityObserver(ability, propertyName);

    return ability[propertyName];
  },

  destroy() {
    this._removeAbilityObserver();
    return this._super(...arguments);
  },

  _addAbilityObserver(ability, propertyName) {
    setProperties(this, { ability, propertyName });
    addObserver(this, `ability.${propertyName}`, this, 'recompute');
  },

  _removeAbilityObserver() {
    removeObserver(this, `ability.${this.propertyName}`, this, 'recompute');
    this.ability && this.ability.destroy();
    setProperties(this, { ability: null, propertyName: null });<commit_msg>use `get` from `@ember/object` to look up `propertyName` on `ability` to avoid issues caused by `unknownProperty` usage<commit_after>import Helper from '@ember/component/helper';
import { inject as service } from '@ember/service';
import { addObserver, removeObserver } from '@ember/object/observers';
import { setProperties, get } from '@ember/object';

export default Helper.extend({
  can: service(),

  ability: null,
  propertyName: null,

  compute([abilityString, model], properties) {
    let { abilityName, propertyName } = this.can.parse(abilityString);
    let ability = this.can.abilityFor(abilityName, model, properties);

    propertyName = ability.parseProperty(propertyName);

    this._removeAbilityObserver();
    this._addAbilityObserver(ability, propertyName);

    return get(ability, propertyName);
  },

  destroy() {
    this._removeAbilityObserver();
    return this._super(...arguments);
  },

  _addAbilityObserver(ability, propertyName) {
    setProperties(this, { ability, propertyName });
    addObserver(this, `ability.${propertyName}`, this, 'recompute');
  },

  _removeAbilityObserver() {
    removeObserver(this, `ability.${this.propertyName}`, this, 'recompute');
    this.ability && this.ability.destroy();
    setProperties(this, { ability: null, propertyName: null });
{'fraction_non_alphanumeric': 0.13690952762209768, 'fraction_numerical': 0.0, 'mean_word_length': 4.95, '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': '4360343', 'n_tokens_mistral': 706, 'n_tokens_neox': 691, 'n_words': 162}