Skip to content

Commit

Permalink
Implement queryManager as a macro
Browse files Browse the repository at this point in the history
This uses `computed` from `@ember-decorators/object`.

This allow us to use computed as a macro in classic ember objects using `EmberOjbect.extend({ ... })` as well as a decorator when using classes.

In the future, `@ember-decorators/object` would only serve us as a polyfill for older Ember versions as this is becoming the default behavior in Ember per [Decorators RFC](emberjs/rfcs#408)
  • Loading branch information
josemarluedke committed Mar 10, 2019
1 parent 53bbf9d commit 49cc204
Showing 1 changed file with 26 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -1,3 +1,29 @@
import { getOwner } from '@ember/application';
import { computed } from '@ember-decorators/object';
import setupHooks from './setup-hooks';

export function queryManager(options = {}) {
let serviceName = 'apollo';
if (typeof options === 'object' && options.service) {
serviceName = options.service;
}

const macro = computed({
get() {
const service = getOwner(this).lookup(`service:${serviceName}`);
const queryManager = new QueryManager(service);
setupHooks(queryManager, this);
return queryManager;
},
});

if (arguments.length > 1) {
return macro(...arguments);
}

return macro;
}

export default class QueryManager {
apollo = undefined;
activeSubscriptions = [];
Expand Down

0 comments on commit 49cc204

Please sign in to comment.