From 44418a2b496ecfbae20590a0c8140a5deacffaab Mon Sep 17 00:00:00 2001 From: Alex Ford Date: Wed, 12 Feb 2020 16:12:15 -0700 Subject: [PATCH 1/2] [feature] support RadarClass component attribute Support instantiating a VerticalCollection Component with a custom Radar using the `RadarClass` attribute. --- .../vertical-collection/component.js | 11 ++++++- tests/integration/basic-test.js | 30 +++++++++++++++++++ 2 files changed, 40 insertions(+), 1 deletion(-) diff --git a/addon/components/vertical-collection/component.js b/addon/components/vertical-collection/component.js index 1b262336..7aabfb8c 100644 --- a/addon/components/vertical-collection/component.js +++ b/addon/components/vertical-collection/component.js @@ -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'), @@ -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') || []; diff --git a/tests/integration/basic-test.js b/tests/integration/basic-test.js index 2bcf51d9..38bb1f6e 100644 --- a/tests/integration/basic-test.js +++ b/tests/integration/basic-test.js @@ -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 { @@ -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` +
+ {{#vertical-collection items + estimateHeight=10 + RadarClass=customRadarClass + as |item i| + }} + + {{item.number}} {{i}} + + {{/vertical-collection}} +
+ `); + + await wait(); + + assert.equal(findAll('vertical-item').length, 10, 'correctly updates the number of items rendered on second pass'); +}); From e87d7f55e8805a64b9f8acd7bd36ec0f59663e02 Mon Sep 17 00:00:00 2001 From: Alex Ford Date: Tue, 18 Feb 2020 14:39:39 -0700 Subject: [PATCH 2/2] [chore] export VirtualComponent for DynamicRadar extensions --- addon/-private/index.js | 1 + 1 file changed, 1 insertion(+) diff --git a/addon/-private/index.js b/addon/-private/index.js index 3aa7e00b..3a3c3ca2 100644 --- a/addon/-private/index.js +++ b/addon/-private/index.js @@ -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';