Skip to content

Commit

Permalink
Added engine service share injection utility, as well as minor update…
Browse files Browse the repository at this point in the history
…s to the universe service
  • Loading branch information
roncodes committed Oct 26, 2023
1 parent 7c47c32 commit 650f986
Show file tree
Hide file tree
Showing 4 changed files with 34 additions and 0 deletions.
8 changes: 8 additions & 0 deletions addon/services/universe.js
Original file line number Diff line number Diff line change
Expand Up @@ -447,6 +447,14 @@ export default class UniverseService extends Service.extend(Evented) {
// create menu item
const menuItem = this._createMenuItem(title, route, options);

// register menu item
if (!this[internalRegistryName]) {
this[internalRegistryName] = {
menuItems: [],
menuPanels: [],
};
}

// register menu item
this[internalRegistryName].menuItems.pushObject(menuItem);

Expand Down
15 changes: 15 additions & 0 deletions addon/utils/inject-engine-service.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
import { getOwner } from '@ember/application';

export default function injectEngineService(target, engineName, serviceName, key = null) {
const owner = getOwner(target);
const universe = owner.lookup('service:universe');
const service = universe.getServiceFromEngine(engineName, serviceName);
const effectiveServiceName = key || serviceName;

Object.defineProperty(target, effectiveServiceName, {
value: service,
writable: false,
configurable: true,
enumerable: true,
});
}
1 change: 1 addition & 0 deletions app/utils/inject-engine-service.js
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export { default } from '@fleetbase/ember-core/utils/inject-engine-service';
10 changes: 10 additions & 0 deletions tests/unit/utils/inject-engine-service-test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
import injectEngineService from 'dummy/utils/inject-engine-service';
import { module, test } from 'qunit';

module('Unit | Utility | inject-engine-service', function () {
// TODO: Replace this with your real tests.
test('it works', function (assert) {
let result = injectEngineService();
assert.ok(result);
});
});

0 comments on commit 650f986

Please sign in to comment.