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

Fix deprecation toc arguments in component lifecycle hooks #691

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
42 changes: 32 additions & 10 deletions addon/components/paper-autocomplete-trigger.js
Original file line number Diff line number Diff line change
Expand Up @@ -39,28 +39,50 @@ export default Component.extend({
}),

// Lifecycle hooks
didUpdateAttrs({ oldAttrs, newAttrs }) {
init() {
this._super(...arguments);
this.set('oldSelect', this.get('select'));
this.set('oldLoading', this.get('loading'));
this.set('oldLastSearchedText', this.get('lastSearchedText'));
},

didUpdateAttrs() {
this._super(...arguments);

let oldSelect = this.get('oldSelect');
let oldLoading = this.get('oldLoading');
let oldLastSearchedText = this.get('oldLastSearchedText');

let select = this.get('select');
let loading = this.get('loading');
let searchText = this.get('searchText');
let lastSearchedText = this.get('lastSearchedText');
let options = this.get('options');

/*
* We need to update the input field with value of the selected option whenever we're closing
* the select box. But we also close the select box when we're loading search results and when
* we remove input text -- so protect against this
*/
if (oldAttrs.select.isOpen && !newAttrs.select.isOpen && !newAttrs.loading && newAttrs.searchText) {
if (oldSelect.isOpen && !select.isOpen && !loading && searchText) {
this.set('text', this.getSelectedAsText());
}

if (newAttrs.lastSearchedText !== oldAttrs.lastSearchedText) {
if (isBlank(newAttrs.lastSearchedText)) {
run.schedule('actions', null, newAttrs.select.actions.close, null, true);
if (lastSearchedText !== oldLastSearchedText) {
if (isBlank(lastSearchedText)) {
run.schedule('actions', null, select.actions.close, null, true);
} else {
run.schedule('actions', null, newAttrs.select.actions.open);
run.schedule('actions', null, select.actions.open);
}
} else if (!isBlank(newAttrs.lastSearchedText) && get(this, 'options.length') === 0 && this.get('loading')) {
run.schedule('actions', null, newAttrs.select.actions.close, null, true);
} else if (oldAttrs.loading && !newAttrs.loading && newAttrs.options.length > 0) {
run.schedule('actions', null, newAttrs.select.actions.open);
} else if (!isBlank(lastSearchedText) && get(this, 'options.length') === 0 && this.get('loading')) {
run.schedule('actions', null, select.actions.close, null, true);
} else if (oldLoading && !loading && options.length > 0) {
run.schedule('actions', null, select.actions.open);
}

this.set('oldSelect', select);
this.set('oldLoading', loading);
this.set('oldLastSearchedText', lastSearchedText);
},

// Actions
Expand Down
29 changes: 21 additions & 8 deletions addon/components/paper-virtual-repeat.js
Original file line number Diff line number Diff line change
Expand Up @@ -117,6 +117,11 @@ const VirtualRepeatComponent = VirtualEachComponent.extend({
return Math.ceil(this.get('itemHeight') ? size / this.get('itemHeight') : 1) + EXTRA_ROW_PADDING;
}).readOnly(),

init() {
this._super(...arguments);
this.set('oldScrollIndex', this.get('scrollIndex'));
},

didInsertElement() {
this._super(...arguments);

Expand All @@ -127,9 +132,15 @@ const VirtualRepeatComponent = VirtualEachComponent.extend({
});
},

didReceiveAttrs(changes) {
didReceiveAttrs() {
this._super(...arguments);
let { newAttrs, oldAttrs = {} } = changes;

let height = this.get('height');
let width = this.get('width');
let scrollIndex = this.get('scrollIndex');
let scrollTop = this.get('scrollTop');

let oldScrollIndex = this.get('oldScrollIndex');

RSVP.cast(this.getAttr('items')).then((attrItems) => {
let items = emberArray(attrItems);
Expand All @@ -141,17 +152,19 @@ const VirtualRepeatComponent = VirtualEachComponent.extend({
});

// Set size explicitly
if (newAttrs.height) {
this.set('size', newAttrs.height);
} else if (newAttrs.width) {
this.set('size', newAttrs.width);
if (height) {
this.set('size', height);
} else if (width) {
this.set('size', width);
}

// Scroll index has changed, load more data & scroll
if (oldAttrs.scrollIndex !== newAttrs.scrollIndex) {
this.scrollToVirtualItem(newAttrs.scrollIndex, newAttrs.scrollTop);
if (oldScrollIndex !== scrollIndex) {
this.scrollToVirtualItem(scrollIndex, scrollTop);
}
});

this.set('oldScrollIndex', scrollIndex);
},

didRender() {
Expand Down