Skip to content

Commit

Permalink
Fix deprecation toc_arguments-in-component-lifecycle-hooks
Browse files Browse the repository at this point in the history
  • Loading branch information
bjornharrtell committed Apr 27, 2017
1 parent e4bf593 commit 0c36d37
Show file tree
Hide file tree
Showing 2 changed files with 53 additions and 18 deletions.
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

0 comments on commit 0c36d37

Please sign in to comment.