Skip to content
This repository has been archived by the owner on Aug 3, 2020. It is now read-only.

Commit

Permalink
Make into a true polyfill
Browse files Browse the repository at this point in the history
Fixes #5.

Why not patch in an initializer? Because then it wouldn't work in places like unit and integration tests.
  • Loading branch information
ef4 committed Dec 6, 2016
1 parent cc60e88 commit b46db82
Show file tree
Hide file tree
Showing 4 changed files with 39 additions and 2 deletions.
4 changes: 4 additions & 0 deletions addon/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,10 @@ import FakeOwner from './fake-owner';

let hasGetOwner = !!Ember.getOwner;

Ember.deprecate("ember-getowner-polyfill is now a true polyfill. Use Ember.getOwner directly instead of importing from ember-getowner-polyfill", false, {
id: "ember-getowner-polyfill.import"

This comment has been minimized.

Copy link
@nightire

nightire Dec 7, 2016

Contributor

option.until is missing, causing another deprecation.

This comment has been minimized.

Copy link
@rwjblue

rwjblue Dec 7, 2016

Member

Good catch, sorry about that

This comment has been minimized.

Copy link
@rwjblue

rwjblue Dec 7, 2016

Member

Mind sending a PR?

});

export default function(object) {
let owner;

Expand Down
22 changes: 21 additions & 1 deletion index.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,25 @@
'use strict';

module.exports = {
name: 'ember-getowner-polyfill'
name: 'ember-getowner-polyfill',
included: function() {
this._ensureThisImport();
this.import('vendor/install-getowner-polyfill.js');
},
_ensureThisImport: function() {
if (!this.import) {
this._findHost = function findHostShim() {
var current = this;
var app;
do {
app = current.app || app;
} while (current.parent.parent && (current = current.parent));
return app;
};
this.import = function importShim(asset, options) {
var app = this._findHost();
app.import(asset, options);
};
}
}
};
2 changes: 1 addition & 1 deletion tests/unit/getowner-test.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import Ember from 'ember';
import getOwner from 'ember-getowner-polyfill';
import { moduleFor, test } from 'ember-qunit';
const { getOwner } = Ember;

moduleFor('foo:bar', {
beforeEach() {
Expand Down
13 changes: 13 additions & 0 deletions vendor/install-getowner-polyfill.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
var Ember = require('ember').default;
if (!Ember.getOwner) {
Object.defineProperty(Ember, 'getOwner', {
get: function() {
var FakeOwner = require('ember-getowner-polyfill/fake-owner').default;
return function(object) {
if (object.container) {
return new FakeOwner(object);
}
};
}
});
}

0 comments on commit b46db82

Please sign in to comment.