Skip to content

Commit

Permalink
[CLEANUP] removed Ember.required
Browse files Browse the repository at this point in the history
  • Loading branch information
bekzod committed Dec 27, 2017
1 parent cd61ae4 commit 7a9723a
Show file tree
Hide file tree
Showing 5 changed files with 26 additions and 12 deletions.
5 changes: 3 additions & 2 deletions packages/ember-metal/lib/mixin.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ import {
deprecate
} from 'ember-debug';
import { DEBUG } from 'ember-env-flags';
import { ENV } from 'ember-environment';
import { descriptorFor, meta as metaFor, peekMeta } from './meta';
import expandProperties from './expand_properties';
import {
Expand Down Expand Up @@ -192,7 +193,7 @@ function applyMergedProperties(obj, key, value, values) {

function addNormalizedProperty(base, key, value, meta, descs, values, concats, mergings) {
if (value instanceof Descriptor) {
if (value === REQUIRED && descs[key]) { return CONTINUE; }
if (ENV._ENABLE_PROPERTY_REQUIRED_SUPPORT && value === REQUIRED && descs[key]) { return CONTINUE; }

// Wrap descriptor function to implement
// _super() if needed
Expand Down Expand Up @@ -355,7 +356,7 @@ function applyMixin(obj, mixins, partial) {
desc = descs[key];
value = values[key];

if (desc === REQUIRED) { continue; }
if (ENV._ENABLE_PROPERTY_REQUIRED_SUPPORT && desc === REQUIRED) { continue; }

while (desc && desc instanceof Alias) {
let followed = followAlias(obj, desc, descs, values);
Expand Down
7 changes: 5 additions & 2 deletions packages/ember-metal/tests/mixin/required_test.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,14 @@ import {
required,
get
} from '../..';
import { ENV } from 'ember-environment';

let PartialMixin, FinalMixin, obj;

let originalEnvVal;
QUnit.module('Module.required', {
setup() {
originalEnvVal = ENV._ENABLE_PROPERTY_REQUIRED_SUPPORT;
ENV._ENABLE_PROPERTY_REQUIRED_SUPPORT = true;
expectDeprecation(() => {
PartialMixin = Mixin.create({
foo: required(),
Expand All @@ -25,6 +28,7 @@ QUnit.module('Module.required', {

teardown() {
PartialMixin = FinalMixin = obj = null;
ENV._ENABLE_PROPERTY_REQUIRED_SUPPORT = originalEnvVal;
}
});

Expand Down Expand Up @@ -54,4 +58,3 @@ QUnit.test('using apply', function() {
mixin(obj, PartialMixin, { foo: 'FOO' });
equal(get(obj, 'foo'), 'FOO', 'should now be defined');
});

10 changes: 6 additions & 4 deletions packages/ember-runtime/lib/system/core_object.js
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ import ActionHandler from '../mixins/action_handler';
import { validatePropertyInjections } from '../inject';
import { assert } from 'ember-debug';
import { DEBUG } from 'ember-env-flags';
import { ENV } from 'ember-environment';
import { MANDATORY_SETTER } from 'ember/features';

const schedule = run.schedule;
Expand Down Expand Up @@ -553,10 +554,6 @@ CoreObject.__super__ = null;

let ClassMixinProps = {

ClassMixin: REQUIRED,

PrototypeMixin: REQUIRED,

isClass: true,

isMethod: false,
Expand Down Expand Up @@ -913,6 +910,11 @@ let ClassMixinProps = {
}
};

if (ENV._ENABLE_PROPERTY_REQUIRED_SUPPORT) {
ClassMixinProps.ClassMixin = REQUIRED;
ClassMixinProps.PrototypeMixin = REQUIRED;
}

function injectedPropertyAssertion() {
assert('Injected properties are invalid', validatePropertyInjections(this));
}
Expand Down
4 changes: 3 additions & 1 deletion packages/ember/lib/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,9 @@ Ember.observersFor = metal.observersFor;
Ember.removeObserver = metal.removeObserver;
Ember._suspendObserver = metal._suspendObserver;
Ember._suspendObservers = metal._suspendObservers;
Ember.required = metal.required;
if (ENV._ENABLE_PROPERTY_REQUIRED_SUPPORT) {
Ember.required = metal.required;
}
Ember.aliasMethod = metal.aliasMethod;
Ember.observer = metal.observer;
Ember.mixin = metal.mixin;
Expand Down
12 changes: 9 additions & 3 deletions packages/ember/tests/reexports_test.js
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
import Ember from '../index';
import { ENV } from 'ember-environment';
import { confirmExport } from 'internal-test-helpers';
import { DEBUG } from 'ember-env-flags';

QUnit.module('ember reexports');

[
let allExports =[
// ember-utils
['getOwner', 'ember-utils', 'getOwner'],
['setOwner', 'ember-utils', 'setOwner'],
Expand Down Expand Up @@ -108,7 +109,6 @@ QUnit.module('ember reexports');
['removeObserver', 'ember-metal'],
['_suspendObserver', 'ember-metal'],
['_suspendObservers', 'ember-metal'],
['required', 'ember-metal'],
['aliasMethod', 'ember-metal'],
['observer', 'ember-metal'],
['mixin', 'ember-metal'],
Expand Down Expand Up @@ -205,7 +205,13 @@ QUnit.module('ember reexports');
// ember-extension-support
['DataAdapter', 'ember-extension-support'],
['ContainerDebugAdapter', 'ember-extension-support']
].forEach(reexport => {
];

if (ENV._ENABLE_PROPERTY_REQUIRED_SUPPORT) {
allExports.push(['required', 'ember-metal']);
}

allExports.forEach(reexport => {
let [path, moduleId, exportName] = reexport;

// default path === exportName if none present
Expand Down

0 comments on commit 7a9723a

Please sign in to comment.