Skip to content

Commit

Permalink
Moving Ember.K to legacy addon
Browse files Browse the repository at this point in the history
  • Loading branch information
thoov committed Nov 30, 2017
1 parent b1adf2b commit d6bc4d1
Show file tree
Hide file tree
Showing 6 changed files with 91 additions and 4 deletions.
6 changes: 5 additions & 1 deletion config/environment.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,9 @@
'use strict';

module.exports = function(/* environment, appConfig */) {
return { };
return {
EmberENV: {
_ENABLE_EMBER_K_SUPPORT: true
}
};
};
8 changes: 7 additions & 1 deletion index.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,11 @@
'use strict';

module.exports = {
name: 'ember-2-legacy'
name: 'ember-2-legacy',

included() {
this._super.included.apply(this, arguments);

this.import('vendor/ember-k.js');
}
};
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@
"ember-disable-prototype-extensions": "^1.1.2",
"ember-export-application-global": "^2.0.0",
"ember-load-initializers": "^1.0.0",
"ember-qunit-assert-helpers": "^0.2.1",
"ember-resolver": "^4.0.0",
"ember-source": "~2.17.0",
"loader.js": "^4.2.3"
Expand Down
27 changes: 27 additions & 0 deletions tests/unit/ember-k-test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
import Ember from 'ember';
import { module, test } from 'qunit';

module('Ember.K');

test('that Ember.K is correctly polyfilled', assert => {
assert.equal(typeof Ember.K, 'function', 'function is defined on Ember');
});

test('that Ember.K properly returns this when invoked', function(assert) {
let Thing = Ember.Object.extend({
randomMethod: Ember.K,
});

let instance = Thing.create();
assert.strictEqual(instance.randomMethod(), instance, 'Ember.K returns this');
});

test('that Ember.K is deprecated', function(assert) {
assert.expectDeprecation(() => {
let obj = {
noop: Ember.K
};

assert.equal(obj, obj.noop());
}, 'Ember.K is deprecated in favor of defining a function inline.');
});
42 changes: 42 additions & 0 deletions vendor/ember-k.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
(function() {
var _Ember;
if (typeof Ember !== 'undefined') {
_Ember = Ember;
} else {
_Ember = require('ember').default;
}

if (EmberENV && EmberENV._ENABLE_EMBER_K_SUPPORT !== true) {
return false;
}

if (_Ember.hasOwnProperty('K')) {
return false;
}

/**
An empty function useful for some operations. Always returns `this`.
@method K
@return {Object}
@public
@deprecated
*/
function deprecatedEmberK() { return this; }

Object.defineProperty(_Ember, 'K', {
get() {
_Ember.deprecate(
'Ember.K is deprecated in favor of defining a function inline.',
false,
{
id: 'ember-metal.ember-k',
until: '3.0.0',
url: 'https://emberjs.com/deprecations/v2.x#toc_code-ember-k-code'
}
);

return deprecatedEmberK;
}
});
})();
11 changes: 9 additions & 2 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -1022,7 +1022,7 @@ broccoli-file-creator@^1.1.1:
rsvp "~3.0.6"
symlink-or-copy "^1.0.1"

broccoli-filter@^1.2.2, broccoli-filter@^1.2.3:
broccoli-filter@^1.0.1, broccoli-filter@^1.2.2, broccoli-filter@^1.2.3:
version "1.2.4"
resolved "https://registry.yarnpkg.com/broccoli-filter/-/broccoli-filter-1.2.4.tgz#409afb94b9a3a6da9fac8134e91e205f40cc7330"
dependencies:
Expand Down Expand Up @@ -1756,7 +1756,7 @@ ember-ajax@^3.0.0:
dependencies:
ember-cli-babel "^6.0.0"

ember-cli-babel@^6.0.0, ember-cli-babel@^6.0.0-beta.7, ember-cli-babel@^6.3.0, ember-cli-babel@^6.6.0, ember-cli-babel@^6.8.1:
ember-cli-babel@^6.0.0, ember-cli-babel@^6.0.0-beta.7, ember-cli-babel@^6.3.0, ember-cli-babel@^6.6.0, ember-cli-babel@^6.8.1, ember-cli-babel@^6.9.0:
version "6.10.0"
resolved "https://registry.yarnpkg.com/ember-cli-babel/-/ember-cli-babel-6.10.0.tgz#81424acd1d97fb13658168121eeb2007d6edee84"
dependencies:
Expand Down Expand Up @@ -2060,6 +2060,13 @@ ember-load-initializers@^1.0.0:
dependencies:
ember-cli-babel "^6.0.0-beta.7"

ember-qunit-assert-helpers@^0.2.1:
version "0.2.1"
resolved "https://registry.yarnpkg.com/ember-qunit-assert-helpers/-/ember-qunit-assert-helpers-0.2.1.tgz#4a77f8ff252e47cc53db6fa7fb4becb426de8d29"
dependencies:
broccoli-filter "^1.0.1"
ember-cli-babel "^6.9.0"

ember-qunit@^3.1.0:
version "3.1.0"
resolved "https://registry.yarnpkg.com/ember-qunit/-/ember-qunit-3.1.0.tgz#4995a6207ab66b5d0cf807d0459d48f55f9eee5f"
Expand Down

0 comments on commit d6bc4d1

Please sign in to comment.