Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[feature] support RadarClass component attribute #314

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions addon/-private/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ export { default as closestElement } from './utils/element/closest';

export { default as DynamicRadar } from './data-view/radar/dynamic-radar';
export { default as StaticRadar } from './data-view/radar/static-radar';
export { default as VirtualComponent } from './data-view/elements/virtual-component';

export { default as ViewportContainer } from './data-view/viewport-container';
export { default as objectAt } from './data-view/utils/object-at';
Expand Down
11 changes: 10 additions & 1 deletion addon/components/vertical-collection/component.js
Original file line number Diff line number Diff line change
Expand Up @@ -149,6 +149,15 @@ const VerticalCollection = Component.extend({
*/
occlusionTagName: 'occluded-content',

RadarClass: computed({
get() {
return this._RadarClass || this.staticHeight ? StaticRadar : DynamicRadar;
},
set(_, value) {
return this._RadarClass = value;
}
}),

isEmpty: empty('items'),
shouldYieldToInverse: readOnly('isEmpty'),

Expand Down Expand Up @@ -217,7 +226,7 @@ const VerticalCollection = Component.extend({
this._super();

this.token = new Token();
const RadarClass = this.staticHeight ? StaticRadar : DynamicRadar;
const RadarClass = this.get('RadarClass');

const items = this.get('items') || [];

Expand Down
30 changes: 30 additions & 0 deletions tests/integration/basic-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import {
} from 'ember-native-dom-helpers';
import wait from 'ember-test-helpers/wait';

import { StaticRadar } from '@html-next/vertical-collection/-private';
import getNumbers from 'dummy/lib/get-numbers';

import {
Expand Down Expand Up @@ -353,3 +354,32 @@ testScenarios(
assert.equal(scrollContainer.scrollTop, 500, 'scroll position remains the same');
}
);

test('The collection renders with a RadarClass set', async function(assert) {
assert.expect(1);

class CustomRadarClass extends StaticRadar {}

this.setProperties({
items: getNumbers(0, 10),
customRadarClass: CustomRadarClass
});

this.render(hbs`
<div style="height: 100px;">
{{#vertical-collection items
estimateHeight=10
RadarClass=customRadarClass
as |item i|
}}
<vertical-item style="height: 10px">
{{item.number}} {{i}}
</vertical-item>
{{/vertical-collection}}
</div>
`);

await wait();

assert.equal(findAll('vertical-item').length, 10, 'correctly updates the number of items rendered on second pass');
});