From 6e1c50d7b3cb01668ee04746474c8662f482b330 Mon Sep 17 00:00:00 2001 From: DrVonDevious Date: Tue, 14 Mar 2023 12:37:02 -0500 Subject: [PATCH 1/4] remove usages of computed.volatile --- addon/components/sortable-group.js | 19 ++++---- addon/mixins/sortable-item.js | 72 +++++++++++++++--------------- 2 files changed, 46 insertions(+), 45 deletions(-) diff --git a/addon/components/sortable-group.js b/addon/components/sortable-group.js index 15937b41..615864e8 100644 --- a/addon/components/sortable-group.js +++ b/addon/components/sortable-group.js @@ -37,22 +37,25 @@ export default Component.extend({ @property itemPosition @type Number */ - itemPosition: computed(function() { + get itemPosition() { let direction = this.get('direction'); return this.get(`sortedItems.firstObject.${direction}`) - this.get('sortedItems.firstObject.spacing'); - }).volatile(), - itemPositionX: computed('sortedItems', function () { + } + + get itemPositionX() { return 0 - this.get('sortedItems.firstObject.spacing'); - }).volatile(), - itemPositionY: computed('sortedItems', function () { + } + + get itemPositionY() { return 0 - this.get('sortedItems.firstObject.spacing'); - }).volatile(), + } + /** @property sortedItems @type Array */ - sortedItems: computed('items', function() { + get sortedItems() { const items = a(this.get('items')); const direction = this.get('direction'); @@ -62,7 +65,7 @@ export default Component.extend({ } else { return items.sortBy(direction); } - }).volatile(), + } /** Register an item with this group. diff --git a/addon/mixins/sortable-item.js b/addon/mixins/sortable-item.js index 3963a737..c63c7043 100644 --- a/addon/mixins/sortable-item.js +++ b/addon/mixins/sortable-item.js @@ -125,21 +125,21 @@ export default Mixin.create({ @property isAnimated @type Boolean */ - isAnimated: computed(function() { + get isAnimated() { if (!this.element) { return; } let el = this.element; let property = getComputedStyle(el).transitionProperty; return /all|transform/.test(property); - }).volatile(), + } /** The current transition duration in milliseconds. @property transitionDuration @type Number */ - transitionDuration: computed(function() { + get transitionDuration() { let el = this.element; let rule = getComputedStyle(el).transitionDuration; let match = rule.match(/([\d.]+)([ms]*)/); @@ -156,57 +156,55 @@ export default Mixin.create({ } return 0; - }).volatile(), + } /** Horizontal position of the item. @property x @type Number */ - x: computed({ - get() { - if (this._x === undefined) { - let marginLeft = parseFloat(getComputedStyle(this.element).marginLeft); - this._x = this.element.scrollLeft + this.element.offsetLeft - marginLeft; - } + get x() { + if (this._x === undefined) { + let marginLeft = parseFloat(getComputedStyle(this.element).marginLeft); + this._x = this.element.scrollLeft + this.element.offsetLeft - marginLeft; + } - return this._x; - }, - set(_, value) { - if (value !== this._x) { - this._x = value; - this._scheduleApplyPosition(); - } - }, - }).volatile(), + return this._x; + } + + set x(_, value) { + if (value !== this._x) { + this._x = value; + this._scheduleApplyPosition(); + } + } /** Vertical position of the item relative to its offset parent. @property y @type Number */ - y: computed({ - get() { - if (this._y === undefined) { - this._y = this.element.offsetTop; - } + get y() { + if (this._y === undefined) { + this._y = this.element.offsetTop; + } - return this._y; - }, - set(key, value) { - if (value !== this._y) { - this._y = value; - this._scheduleApplyPosition(); - } + return this._y; + } + + set y(key, value) { + if (value !== this._y) { + this._y = value; + this._scheduleApplyPosition(); } - }).volatile(), + } /** Width of the item. @property height @type Number */ - width: computed(function() { + get width() { let el = this.element; let width = el.offsetWidth; let elStyles = getComputedStyle(el); @@ -217,14 +215,14 @@ export default Mixin.create({ width += getBorderSpacing(el).horizontal; return width; - }).volatile(), + } /** Height of the item including margins. @property height @type Number */ - height: computed(function() { + get height() { let el = this.element; let height = el.offsetHeight; @@ -234,7 +232,7 @@ export default Mixin.create({ height += getBorderSpacing(el).vertical; return height; - }).volatile(), + } /** @private @@ -705,7 +703,7 @@ export default Mixin.create({ if (this.get('isAnimated')) { duration = this.get('transitionDuration'); } - + run.later(this, resolve, duration); }) }); From ab3be7d8cbd8c9e5f72abebed4f945a805e77816 Mon Sep 17 00:00:00 2001 From: DrVonDevious Date: Tue, 14 Mar 2023 12:52:47 -0500 Subject: [PATCH 2/4] fix missing commas --- addon/components/sortable-group.js | 8 ++++---- addon/mixins/sortable-item.js | 20 ++++++++++---------- 2 files changed, 14 insertions(+), 14 deletions(-) diff --git a/addon/components/sortable-group.js b/addon/components/sortable-group.js index 615864e8..40946684 100644 --- a/addon/components/sortable-group.js +++ b/addon/components/sortable-group.js @@ -41,15 +41,15 @@ export default Component.extend({ let direction = this.get('direction'); return this.get(`sortedItems.firstObject.${direction}`) - this.get('sortedItems.firstObject.spacing'); - } + }, get itemPositionX() { return 0 - this.get('sortedItems.firstObject.spacing'); - } + }, get itemPositionY() { return 0 - this.get('sortedItems.firstObject.spacing'); - } + }, /** @property sortedItems @@ -65,7 +65,7 @@ export default Component.extend({ } else { return items.sortBy(direction); } - } + }, /** Register an item with this group. diff --git a/addon/mixins/sortable-item.js b/addon/mixins/sortable-item.js index c63c7043..7e4cb608 100644 --- a/addon/mixins/sortable-item.js +++ b/addon/mixins/sortable-item.js @@ -132,7 +132,7 @@ export default Mixin.create({ let property = getComputedStyle(el).transitionProperty; return /all|transform/.test(property); - } + }, /** The current transition duration in milliseconds. @@ -156,7 +156,7 @@ export default Mixin.create({ } return 0; - } + }, /** Horizontal position of the item. @@ -170,14 +170,14 @@ export default Mixin.create({ } return this._x; - } + }, - set x(_, value) { + set x(value) { if (value !== this._x) { this._x = value; this._scheduleApplyPosition(); } - } + }, /** Vertical position of the item relative to its offset parent. @@ -190,14 +190,14 @@ export default Mixin.create({ } return this._y; - } + }, - set y(key, value) { + set y(value) { if (value !== this._y) { this._y = value; this._scheduleApplyPosition(); } - } + }, /** Width of the item. @@ -215,7 +215,7 @@ export default Mixin.create({ width += getBorderSpacing(el).horizontal; return width; - } + }, /** Height of the item including margins. @@ -232,7 +232,7 @@ export default Mixin.create({ height += getBorderSpacing(el).vertical; return height; - } + }, /** @private From e7b8c83128a72886b7b1a4a158b284349cb448d5 Mon Sep 17 00:00:00 2001 From: DrVonDevious Date: Mon, 20 Mar 2023 08:45:39 -0500 Subject: [PATCH 3/4] replace sendAction calls with direct function calls --- addon/components/sortable-group.js | 8 ++++++-- addon/mixins/sortable-item.js | 8 ++++++-- 2 files changed, 12 insertions(+), 4 deletions(-) diff --git a/addon/components/sortable-group.js b/addon/components/sortable-group.js index 40946684..5b5f66a8 100644 --- a/addon/components/sortable-group.js +++ b/addon/components/sortable-group.js @@ -217,9 +217,13 @@ export default Component.extend({ }); if (groupModel !== NO_MODEL) { - this.sendAction('onChange', groupModel, itemModels, draggedModel); + if (typeof this['onChange'] === 'function') { + this['onChange'](groupModel, itemModels, draggedModel); + } } else { - this.sendAction('onChange', itemModels, draggedModel); + if (typeof this['onChange'] === 'function') { + this['onChange'](itemModels, draggedModel); + } } }, diff --git a/addon/mixins/sortable-item.js b/addon/mixins/sortable-item.js index 7e4cb608..40a10b85 100644 --- a/addon/mixins/sortable-item.js +++ b/addon/mixins/sortable-item.js @@ -403,7 +403,9 @@ export default Mixin.create({ this._tellGroup('prepare'); this.set('isDragging', true); - this.sendAction('onDragStart', this.get('model')); + if (typeof this['onDragStart'] === 'function') { + this['onDragStart'](this.get('model')); + } this._scrollOnEdges(drag); }, @@ -714,7 +716,9 @@ export default Mixin.create({ @private */ _complete() { - this.sendAction('onDragStop', this.get('model')); + if (typeof this['onDragStop'] === 'function') { + this['onDragStop'](this.get('model')); + } this.set('isDropping', false); this.set('wasDropped', true); this._tellGroup('commit'); From 5508808f44b216710ee25b0523cab75306555627 Mon Sep 17 00:00:00 2001 From: DrVonDevious Date: Mon, 20 Mar 2023 11:23:22 -0500 Subject: [PATCH 4/4] fix Ember.get call syntax --- addon/components/sortable-group.js | 36 +++++++++++++++--------------- 1 file changed, 18 insertions(+), 18 deletions(-) diff --git a/addon/components/sortable-group.js b/addon/components/sortable-group.js index 5b5f66a8..b881a7f2 100644 --- a/addon/components/sortable-group.js +++ b/addon/components/sortable-group.js @@ -38,17 +38,17 @@ export default Component.extend({ @type Number */ get itemPosition() { - let direction = this.get('direction'); + let direction = get(this, 'direction'); - return this.get(`sortedItems.firstObject.${direction}`) - this.get('sortedItems.firstObject.spacing'); + return get(this, `sortedItems.firstObject.${direction}`) - get(this, 'sortedItems.firstObject.spacing'); }, get itemPositionX() { - return 0 - this.get('sortedItems.firstObject.spacing'); + return 0 - get(this, 'sortedItems.firstObject.spacing'); }, get itemPositionY() { - return 0 - this.get('sortedItems.firstObject.spacing'); + return 0 - get(this, 'sortedItems.firstObject.spacing'); }, /** @@ -56,8 +56,8 @@ export default Component.extend({ @type Array */ get sortedItems() { - const items = a(this.get('items')); - const direction = this.get('direction'); + const items = a(get(this, 'items')); + const direction = get(this, 'direction'); if (direction.length === 2) { const [first, second] = direction.split(''); @@ -73,7 +73,7 @@ export default Component.extend({ @param {SortableItem} [item] */ registerItem(item) { - this.get('items').addObject(item); + get(this, 'items').addObject(item); }, /** @@ -82,7 +82,7 @@ export default Component.extend({ @param {SortableItem} [item] */ deregisterItem(item) { - this.get('items').removeObject(item); + get(this, 'items').removeObject(item); }, /** @@ -92,9 +92,9 @@ export default Component.extend({ @method prepare */ prepare() { - this._itemPosition = this.get('itemPosition'); - this._itemPositionX = this.get('itemPositionX'); - this._itemPositionY = this.get('itemPositionY'); + this._itemPosition = get(this, 'itemPosition'); + this._itemPositionX = get(this, 'itemPositionX'); + this._itemPositionY = get(this, 'itemPositionY'); }, /** @@ -102,7 +102,7 @@ export default Component.extend({ @method update */ update() { - let sortedItems = this.get('sortedItems'); + let sortedItems = get(this, 'sortedItems'); // Position of the first element let position = this._itemPosition; let positionX = this._itemPositionX; @@ -110,13 +110,13 @@ export default Component.extend({ // Just in case we haven’t called prepare first. if (position === undefined) { - position = this.get('itemPosition'); + position = get(this, 'itemPosition'); } if (positionX === undefined) { - positionX = this.get('itemPositionX'); + positionX = get(this, 'itemPositionX'); } if (positionY === undefined) { - positionY = this.get('itemPositionY'); + positionY = get(this, 'itemPositionY'); } let startX = positionX; @@ -128,7 +128,7 @@ export default Component.extend({ return !item.isDragging; }).uniqBy('x').length; sortedItems.forEach((item, index) => { - let direction = this.get('direction'); + let direction = get(this, 'direction'); if (get(this, 'direction').length > 1) { if (!get(item, 'isDragging')) { if (this._hasX(direction)) { @@ -187,8 +187,8 @@ export default Component.extend({ @method commit */ commit() { - let items = this.get('sortedItems'); - let groupModel = this.get('model'); + let items = get(this, 'sortedItems'); + let groupModel = get(this, 'model'); let itemModels = items.mapBy('model'); let draggedItem = items.findBy('wasDropped', true); let draggedModel;