How to use the ember-metal/observer function in ember-metal

To help you get started, we’ve selected a few ember-metal examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github TryGhost / Ghost-Admin / app / components / gh-spin-button.js View on Github external
// Disable Button when isLoading equals true
    attributeBindings: ['disabled', 'type', 'tabindex'],

    // Must be set on the controller
    disabled: equal('showSpinner', true),

    click() {
        if (this.get('action')) {
            this.sendAction('action');
            return false;
        }
        return true;
    },

    toggleSpinner: observer('submitting', function () {
        let submitting = this.get('submitting');
        let timeout = this.get('showSpinnerTimeout');
        let delay = testing ? 10 : 1000;

        if (submitting) {
            this.set('showSpinner', true);
            this.set('showSpinnerTimeout', run.later(this, function () {
                if (!this.get('submitting')) {
                    this.set('showSpinner', false);
                }
                this.set('showSpinnerTimeout', null);
            }, delay));
        } else if (!submitting && timeout === null) {
            this.set('showSpinner', false);
        }
    }),
github hummingbird-me / hummingbird-client / app / components / paginated-resource / infinite.js View on Github external
didInsertElement() {
    this._super(...arguments);
    this._setupViewport();
  },

  willDestroyElement() {
    this._super(...arguments);
    const element = get(this, 'element');
    get(this, 'watcher').unwatch(element);
  },

  /**
   * Remove the spaniel watcher when we don't have a nextLink anymore
   */
  _disableWhenLast: observer('nextLink', function() {
    if (isEmpty(get(this, 'nextLink'))) {
      const element = get(this, 'element');
      get(this, 'watcher').unwatch(element);
    }
  }),

  _setupViewport() {
    const element = get(this, 'element');
    spaniel.scheduleWork(() => {
      get(this, 'watcher').watch(element, () => {
        get(this, 'getNextData').perform();
      });
    });
  },

  _getRootMargin() {
github romulomachado / ember-cli-string-helpers / addon / helpers / find-by.js View on Github external
let byPath = get(this, 'byPath');

    if (isEmpty(byPath)) {
      defineProperty(this, 'content', []);
      return;
    }

    defineProperty(this, 'content', computed(`array.@each.${byPath}`, 'value', function() {
      let array = get(this, 'array');
      let value = get(this, 'value');

      return emberArray(array).findBy(byPath, value);
    }));
  }),

  contentDidChange: observer('content', function() {
    this.recompute();
  })
});
github romulomachado / ember-cli-string-helpers / addon / helpers / reject-by.js View on Github external
if (isPresent(value)) {
      if (typeof value === 'function') {
        filterFn = (item) => !value(get(item, byPath));
      } else {
        filterFn = (item) => get(item, byPath) !== value;
      }
    } else {
      filterFn = (item) => isEmpty(get(item, byPath));
    }

    let cp = filter(`array.@each.${byPath}`, filterFn);

    defineProperty(this, 'content', cp);
  }),

  contentDidChange: observer('content', function() {
    this.recompute();
  })
});
github romulomachado / ember-cli-string-helpers / addon / helpers / find-by.js View on Github external
import set from 'ember-metal/set';
import { A as emberArray } from 'ember-array/utils';
import { isEmpty } from 'ember-utils';

const { defineProperty } = Ember;

export default Helper.extend({
  compute([byPath, value, array]) {
    set(this, 'array', array);
    set(this, 'byPath', byPath);
    set(this, 'value', value);

    return get(this, 'content');
  },

  byPathDidChange: observer('byPath', function() {
    let byPath = get(this, 'byPath');

    if (isEmpty(byPath)) {
      defineProperty(this, 'content', []);
      return;
    }

    defineProperty(this, 'content', computed(`array.@each.${byPath}`, 'value', function() {
      let array = get(this, 'array');
      let value = get(this, 'value');

      return emberArray(array).findBy(byPath, value);
    }));
  }),

  contentDidChange: observer('content', function() {
github romulomachado / ember-cli-string-helpers / addon / helpers / take.js View on Github external
import Helper from 'ember-helper';
import observer from 'ember-metal/observer';
import set from 'ember-metal/set';

export default Helper.extend({
  compute([takeAmount, array]) {
    set(this, 'array', array);
    return array.slice(0, takeAmount);
  },

  arrayContentDidChange: observer('array.[]', function() {
    this.recompute();
  })
});
github romulomachado / ember-cli-string-helpers / addon / -private / create-multi-array-helper.js View on Github external
valuesDidChange: observer('arrays.[]', function() {
      this._recomputeArrayKeys();

      let arrays = get(this, 'arrays');
      let arrayKeys = get(this, 'arrayKeys');

      if (isEmpty(arrays)) {
        defineProperty(this, 'content', []);
        return;
      }

      defineProperty(this, 'content', multiArrayComputed(...arrayKeys));
    }),

    contentDidChange: observer('content.[]', function() {
      this.recompute();
    }),

    _recomputeArrayKeys() {
      let arrays = get(this, 'arrays');

      let oldArrayKeys = get(this, 'arrayKeys') || [];
      let newArrayKeys = arrays.map(idForArray);

      let keysToRemove = oldArrayKeys.filter((key) => {
        return newArrayKeys.indexOf(key) === -1;
      });

      keysToRemove.forEach((key) => set(this, key, null));
      arrays.forEach((array) => set(this, idForArray(array), array));
github romulomachado / ember-cli-string-helpers / addon / -private / create-multi-array-helper.js View on Github external
export default function(multiArrayComputed) {
  return Helper.extend({
    compute([...arrays]) {
      set(this, 'arrays', arrays.map((obj) => {
        if (isEmberArray(obj)) {
          return emberArray(obj);
        }

        return obj;
      }));

      return get(this, 'content');
    },

    valuesDidChange: observer('arrays.[]', function() {
      this._recomputeArrayKeys();

      let arrays = get(this, 'arrays');
      let arrayKeys = get(this, 'arrayKeys');

      if (isEmpty(arrays)) {
        defineProperty(this, 'content', []);
        return;
      }

      defineProperty(this, 'content', multiArrayComputed(...arrayKeys));
    }),

    contentDidChange: observer('content.[]', function() {
      this.recompute();
    }),
github romulomachado / ember-cli-string-helpers / addon / -private / create-needle-haystack-helper.js View on Github external
}).readOnly(),

    compute([needle, option, haystack]) {
      if (isEmpty(haystack)) {
        haystack = option;
        option = null;
      }

      set(this, 'needle', needle);
      set(this, 'haystack', haystack);
      set(this, 'option', option);

      return get(this, 'content');
    },

    contentDidChange: observer('content', function() {
      this.recompute();
    })
  });
}
github romulomachado / ember-cli-string-helpers / addon / helpers / chunk.js View on Github external
export default Helper.extend({
  content: computed('num', 'array.[]', function() {
    let array = get(this, 'array');
    let num = get(this, 'num');

    return chunk(num, array);
  }),

  compute([num, array]) {
    set(this, 'array', array);
    set(this, 'num', num);

    return get(this, 'content');
  },

  contentDidChange: observer('content', function() {
    this.recompute();
  })
});