Skip to content

Commit

Permalink
Remove an implicit injection
Browse files Browse the repository at this point in the history
Because that's deprecated in Ember 3.26
  • Loading branch information
boris-petrov committed Mar 23, 2021
1 parent 71f473c commit 3177024
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 1 deletion.
13 changes: 13 additions & 0 deletions addon/components/draggable-object-target.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import { getOwner } from '@ember/application';
import Component from '@ember/component';
import Droppable from 'ember-drag-drop/mixins/droppable';

Expand All @@ -6,6 +7,18 @@ export default Component.extend(Droppable, {
overrideClass: 'draggable-object-target',
isOver: false,

// idea taken from https://github.com/emberjs/rfcs/blob/master/text/0680-implicit-injection-deprecation.md#stage-1
get coordinator() {
if (this._coordinator === undefined) {
this._coordinator = getOwner(this).lookup('drag:coordinator');
}

return this._coordinator;
},
set coordinator(value) {
this._coordinator = value;
},

handlePayload(payload, event) {
let obj = this.get('coordinator').getObject(payload,{target: this});
this.get('action')(obj, { target: this, event: event });
Expand Down
13 changes: 13 additions & 0 deletions addon/components/draggable-object.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import { getOwner } from '@ember/application';
import Component from '@ember/component';
import { inject as service} from '@ember/service';
import { alias } from '@ember/object/computed';
Expand All @@ -17,6 +18,18 @@ export default Component.extend({
sortingScope: 'drag-objects',
title: alias('content.title'),

// idea taken from https://github.com/emberjs/rfcs/blob/master/text/0680-implicit-injection-deprecation.md#stage-1
get coordinator() {
if (this._coordinator === undefined) {
this._coordinator = getOwner(this).lookup('drag:coordinator');
}

return this._coordinator;
},
set coordinator(value) {
this._coordinator = value;
},

draggable: computed('isDraggable', function() {
let isDraggable = this.get('isDraggable');

Expand Down
1 change: 0 additions & 1 deletion app/initializers/coordinator-setup.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,5 @@ export default {
initialize: function() {
let app = arguments[1] || arguments[0];
app.register("drag:coordinator",Coordinator);
app.inject("component","coordinator","drag:coordinator");
}
};

0 comments on commit 3177024

Please sign in to comment.