Skip to content

Commit a17afd0

Browse files
committed
[Bug]: MutableArray/EmberArray changes is not tracked
1 parent 66fb044 commit a17afd0

File tree

1 file changed

+85
-1
lines changed
  • packages/@ember/-internals/glimmer/tests/integration/components

1 file changed

+85
-1
lines changed

packages/@ember/-internals/glimmer/tests/integration/components/tracked-test.js

+85-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,10 @@
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';
28
import {
39
computed,
410
get,
@@ -580,6 +586,84 @@ moduleFor(
580586

581587
this.assertText('1');
582588
}
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+
}
583667
}
584668
);
585669

0 commit comments

Comments
 (0)