Skip to content

Commit

Permalink
make lt-body.inViewport event deprecated in favour of enterViewport a…
Browse files Browse the repository at this point in the history
…nd test
  • Loading branch information
fran-worley committed May 26, 2019
1 parent b16a45b commit e8ef2ab
Show file tree
Hide file tree
Showing 2 changed files with 41 additions and 1 deletion.
19 changes: 18 additions & 1 deletion addon/components/lt-body.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import Component from '@ember/component';
import { deprecate } from '@ember/application/deprecations';
import { computed, observer } from '@ember/object';
import layout from 'ember-light-table/templates/components/lt-body';
import { run } from '@ember/runloop';
Expand Down Expand Up @@ -527,12 +528,28 @@ export default Component.extend({
this.onScroll(...arguments);
},

/**
* lt-infinity action to determine if component is still in viewport. Deprecated - please use enterViewport
* @event inViewport
* @deprecated Use `enterViewport` instead.
*/
inViewport: null,

/**
* lt-infinity action to determine if component is still in viewport
* @event enterViewport
*/
enterViewport() {
this.set('isInViewport', true);
const inViewport = this.get('inViewport');
if (inViewport) {
deprecate('lt-infinity inViewport event is deprecated please use enterViewport instead', false, {
id: 'ember-light-table.inViewport',
until: '2.0.0'
});
inViewport();
} else {
this.set('isInViewport', true);
}
},
/**
* lt-infinity action to determine if component has exited the viewport
Expand Down
23 changes: 23 additions & 0 deletions tests/integration/components/light-table-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,29 @@ module('Integration | Component | light table', function(hooks) {
await triggerEvent(scrollContainer, 'scroll');
});

test('lt-body inViewport event deprecated', async function(assert) {
assert.expect(2);
this.set('table', new Table(Columns, this.server.createList('user', 5)));
this.set('isInViewport', false);
this.set('inViewport', () => {
assert.ok(true);
this.set('isInViewport', true);
});
this.set('onScrolledToBottom', () => {
assert.ok(true);
});

await render(hbs `
{{#light-table table height='40vh' id="table" as |t|}}
{{t.head fixed=true}}
{{t.body isInViewport=isInViewport inViewport=(action inViewport) onScrolledToBottom=(action onScrolledToBottom)}}
{{/light-table}}
`);
let scrollContainer = find('#table .tse-scroll-content');
scrollContainer.scrollTop = 2501;
await triggerEvent(scrollContainer, 'scroll');
});

test('fixed header', async function(assert) {
assert.expect(2);
this.set('table', new Table(Columns, this.server.createList('user', 5)));
Expand Down

0 comments on commit e8ef2ab

Please sign in to comment.