Sha256: e17bfbf9eb29f6d728ef404c28bdb12b9df68426bb4994225a27467805b3e1f3

Contents?: true

Size: 1.71 KB

Versions: 2

Compression:

Stored size: 1.71 KB

Contents

import { set } from 'ember-metal';
import ArrayProxy from '../../../lib/system/array_proxy';
import { A } from '../../../lib/mixins/array';
import { moduleFor, AbstractTestCase } from 'internal-test-helpers';

moduleFor(
  'ArrayProxy - array observers',
  class extends AbstractTestCase {
    ['@test mutating content'](assert) {
      assert.expect(4);

      let content = A(['x', 'y', 'z']);
      let proxy = ArrayProxy.create({ content });

      proxy.addArrayObserver({
        arrayWillChange(proxy, startIndex, removeCount, addCount) {
          assert.deepEqual([startIndex, removeCount, addCount], [1, 1, 3]);
          assert.deepEqual(proxy.toArray(), ['x', 'y', 'z']);
        },
        arrayDidChange(proxy, startIndex, removeCount, addCount) {
          assert.deepEqual([startIndex, removeCount, addCount], [1, 1, 3]);
          assert.deepEqual(proxy.toArray(), ['x', 'a', 'b', 'c', 'z']);
        },
      });

      proxy.toArray();
      content.replace(1, 1, ['a', 'b', 'c']);
    }

    ['@test assigning content'](assert) {
      assert.expect(4);

      let content = A(['x', 'y', 'z']);
      let proxy = ArrayProxy.create({ content });

      proxy.addArrayObserver({
        arrayWillChange(proxy, startIndex, removeCount, addCount) {
          assert.deepEqual([startIndex, removeCount, addCount], [0, 3, 5]);
          assert.deepEqual(proxy.toArray(), ['x', 'y', 'z']);
        },
        arrayDidChange(proxy, startIndex, removeCount, addCount) {
          assert.deepEqual([startIndex, removeCount, addCount], [0, 3, 5]);
          assert.deepEqual(proxy.toArray(), ['a', 'b', 'c', 'd', 'e']);
        },
      });

      proxy.toArray();
      set(proxy, 'content', A(['a', 'b', 'c', 'd', 'e']));
    }
  }
);

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
discourse-ember-source-3.5.1.1 dist/es/ember-runtime/tests/system/array_proxy/array_observer_test.js
discourse-ember-source-3.5.1.0 dist/dist/es/ember-runtime/tests/system/array_proxy/array_observer_test.js