Sha256: 8e4a63b9b1386284945691785716c506e2d97abe6962062b27114644851037af

Contents?: true

Size: 1.72 KB

Versions: 1

Compression:

Stored size: 1.72 KB

Contents

import { set } from '@ember/-internals/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

1 entries across 1 versions & 1 rubygems

Version Path
discourse-ember-source-3.6.0.0 dist/es/@ember/-internals/runtime/tests/system/array_proxy/array_observer_test.js