Exemplo n.º 1
0
QUnit.test('should notify enumerable observers when called with no params', function() {
  arrayContentWillChange(obj);
  deepEqual(observer._before, [obj, null, null], 'before');

  arrayContentDidChange(obj);
  deepEqual(observer._after, [obj, null, null], 'after');
});
Exemplo n.º 2
0
QUnit.test('should notify when called with diff length items', function() {
  arrayContentWillChange(obj, 0, 2, 1);
  deepEqual(observer._before, [obj, ['ITEM-0', 'ITEM-1'], 1], 'before');

  arrayContentDidChange(obj, 0, 2, 1);
  deepEqual(observer._after, [obj, 2, ['ITEM-0']], 'after');
});
Exemplo n.º 3
0
QUnit.test('should notify when called with same length items', function() {
  arrayContentWillChange(obj, 0, 1, 1);
  deepEqual(observer._before, [obj, 0, 1, 1]);

  arrayContentDidChange(obj, 0, 1, 1);
  deepEqual(observer._after, [obj, 0, 1, 1]);
});
Exemplo n.º 4
0
QUnit.test('should notify when passed lengths are different', function() {
  arrayContentWillChange(obj, 0, 1, 2);
  equal(obj._after, 0);

  arrayContentDidChange(obj, 0, 1, 2);
  equal(obj._after, 1);
});
Exemplo n.º 5
0
QUnit.test('should notify observers when call with no params', function() {
  arrayContentWillChange(obj);
  equal(obj._after, 0);

  arrayContentDidChange(obj);
  equal(obj._after, 1);
});
Exemplo n.º 6
0
QUnit.test('removing enumerable observer should disable', function() {
  obj.removeEnumerableObserver(observer);
  arrayContentWillChange(obj);
  deepEqual(observer._before, null, 'before');

  arrayContentDidChange(obj);
  deepEqual(observer._after, null, 'after');
});
Exemplo n.º 7
0
QUnit.test('should notify observers of []', function() {
  obj = DummyArray.extend({
    enumerablePropertyDidChange: emberObserver('[]', function() {
      this._count++;
    })
  }).create({
    _count: 0
  });

  equal(obj._count, 0, 'should not have invoked yet');

  arrayContentWillChange(obj, 0, 1, 1);
  arrayContentDidChange(obj, 0, 1, 1);

  equal(obj._count, 1, 'should have invoked');
});
Exemplo n.º 8
0
*/
const TestArray = EmberObject.extend(EmberArray, {
  _content: null,

  init(ary = []) {
    this._content = ary;
  },

  // some methods to modify the array so we can test changes.  Note that
  // arrays can be modified even if they don't implement MutableArray.  The
  // MutableArray is just a standard API for mutation but not required.
  addObject(obj) {
    let idx = this._content.length;
    arrayContentWillChange(this, idx, 0, 1);
    this._content.push(obj);
    arrayContentDidChange(this, idx, 0, 1);
  },

  removeFirst(idx) {
    arrayContentWillChange(this, 0, 1, 0);
    this._content.shift();
    arrayContentDidChange(this, 0, 1, 0);
  },

  objectAt(idx) {
    return this._content[idx];
  },

  length: computed(function() {
    return this._content.length;
  })