|
1 |
| -import { Object as EmberObject, A, ArrayProxy, PromiseProxyMixin } from '@ember/-internals/runtime'; |
| 1 | +import { |
| 2 | + Object as EmberObject, |
| 3 | + A, |
| 4 | + ArrayProxy, |
| 5 | + MutableArray, |
| 6 | + PromiseProxyMixin |
| 7 | +} from '@ember/-internals/runtime'; |
2 | 8 | import {
|
3 | 9 | computed,
|
4 | 10 | get,
|
@@ -580,6 +586,84 @@ moduleFor(
|
580 | 586 |
|
581 | 587 | this.assertText('1');
|
582 | 588 | }
|
| 589 | + |
| 590 | + '@test getters update when native array is updated'() { |
| 591 | + class ChildrenComponent extends GlimmerishComponent { |
| 592 | + get countAlias() { |
| 593 | + return get(this, 'args.children.length'); |
| 594 | + } |
| 595 | + |
| 596 | + addChild() { |
| 597 | + this.args.children.pushObject({ id: '1' }); |
| 598 | + } |
| 599 | + } |
| 600 | + |
| 601 | + this.registerComponent('child-count', { |
| 602 | + ComponentClass: ChildrenComponent, |
| 603 | + template: '<button {{action this.addChild}}>{{this.countAlias}}</button>', |
| 604 | + }); |
| 605 | + |
| 606 | + this.render('<ChildCount @children={{this.children}} />', { |
| 607 | + children: A(), |
| 608 | + }); |
| 609 | + |
| 610 | + this.assertText('0'); |
| 611 | + |
| 612 | + runTask(() => this.$('button').click()); |
| 613 | + |
| 614 | + this.assertText('1'); |
| 615 | + } |
| 616 | + |
| 617 | + '@test getters update when MutableArray is updated'() { |
| 618 | + let ArrayOfChildren = EmberObject.extend(MutableArray, { |
| 619 | + _content: null, |
| 620 | + |
| 621 | + init() { |
| 622 | + this._content = A(); |
| 623 | + this._length = 0; |
| 624 | + }, |
| 625 | + |
| 626 | + addObject(obj) { |
| 627 | + this._content.pushObject(obj); |
| 628 | + }, |
| 629 | + |
| 630 | + objectAt(idx) { |
| 631 | + return this._content[idx]; |
| 632 | + }, |
| 633 | + |
| 634 | + get length() { |
| 635 | + return this._length; |
| 636 | + }, |
| 637 | + set length(value) { |
| 638 | + this._length = value; |
| 639 | + }, |
| 640 | + }); |
| 641 | + |
| 642 | + class ChildrenComponent extends GlimmerishComponent { |
| 643 | + get countAlias() { |
| 644 | + return get(this, 'args.children.length'); |
| 645 | + } |
| 646 | + |
| 647 | + addChild() { |
| 648 | + this.args.children.addObject({ id: '1' }); |
| 649 | + } |
| 650 | + } |
| 651 | + |
| 652 | + this.registerComponent('child-count', { |
| 653 | + ComponentClass: ChildrenComponent, |
| 654 | + template: '<button {{action this.addChild}}>{{this.countAlias}}</button>', |
| 655 | + }); |
| 656 | + |
| 657 | + this.render('<ChildCount @children={{this.children}} />', { |
| 658 | + children: ArrayOfChildren.create(), |
| 659 | + }); |
| 660 | + |
| 661 | + this.assertText('0'); |
| 662 | + |
| 663 | + runTask(() => this.$('button').click()); |
| 664 | + |
| 665 | + this.assertText('1'); |
| 666 | + } |
583 | 667 | }
|
584 | 668 | );
|
585 | 669 |
|
|
0 commit comments