From 1e99c3e9796ea98202fa8af14ab84d72711483d3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Gast=C3=B3n=20I=2E=20Silva?= Date: Mon, 27 Mar 2017 14:48:15 -0700 Subject: [PATCH 1/4] wip --- packages/ember-glimmer/lib/component.js | 57 ++++--------------- packages/ember-metal/lib/mixin.js | 26 +++++++++ .../ember-metal/tests/mixin/computed_test.js | 13 +++++ .../ember-metal/tests/mixin/method_test.js | 12 ++++ 4 files changed, 61 insertions(+), 47 deletions(-) diff --git a/packages/ember-glimmer/lib/component.js b/packages/ember-glimmer/lib/component.js index 01da92dab86..bd99576c863 100644 --- a/packages/ember-glimmer/lib/component.js +++ b/packages/ember-glimmer/lib/component.js @@ -637,7 +637,7 @@ const Component = CoreView.extend( readDOMAttr(name) { let element = getViewElement(this); return readDOMAttr(element, name); - } + }, /** The WAI-ARIA role of the control represented by this view. For example, a @@ -717,24 +717,7 @@ const Component = CoreView.extend( @public @since 1.13.0 */ - - /** - Called when the attributes passed into the component have been updated. - Called both during the initial render of a container and during a rerender. - Can be used in place of an observer; code placed here will be executed - every time any attribute updates. - @event didReceiveAttrs - @public - @since 1.13.0 - */ - - /** - Called after a component has been rendered, both on initial render and - in subsequent rerenders. - @method didRender - @public - @since 1.13.0 - */ + didReceiveAttrs() {}, /** Called after a component has been rendered, both on initial render and @@ -743,14 +726,7 @@ const Component = CoreView.extend( @public @since 1.13.0 */ - - /** - Called before a component has been rendered, both on initial render and - in subsequent rerenders. - @method willRender - @public - @since 1.13.0 - */ + didRender() {}, /** Called before a component has been rendered, both on initial render and @@ -759,6 +735,7 @@ const Component = CoreView.extend( @public @since 1.13.0 */ + willRender() {}, /** Called when the attributes passed into the component have been changed. @@ -767,14 +744,7 @@ const Component = CoreView.extend( @public @since 1.13.0 */ - - /** - Called when the attributes passed into the component have been changed. - Called only during a rerender, not during an initial render. - @event didUpdateAttrs - @public - @since 1.13.0 - */ + didUpdateAttrs() {}, /** Called when the component is about to update and rerender itself. @@ -783,14 +753,7 @@ const Component = CoreView.extend( @public @since 1.13.0 */ - - /** - Called when the component is about to update and rerender itself. - Called only during a rerender, not during an initial render. - @event willUpdate - @public - @since 1.13.0 - */ + willUpdate() {}, /** Called when the component has updated and rerendered itself. @@ -799,14 +762,14 @@ const Component = CoreView.extend( @public @since 1.13.0 */ + didUpdate() {}, /** - Called when the component has updated and rerendered itself. - Called only during a rerender, not during an initial render. - @event didUpdate + @event didDestroyElement @public - @since 1.13.0 + @since 2.13.0 */ + didDestroyElement() {} /** A component may contain a layout. A layout is a regular template but diff --git a/packages/ember-metal/lib/mixin.js b/packages/ember-metal/lib/mixin.js index fa3c7ab5853..77418887479 100644 --- a/packages/ember-metal/lib/mixin.js +++ b/packages/ember-metal/lib/mixin.js @@ -95,6 +95,15 @@ function giveDescriptorSuper(meta, key, property, values, descs, base) { } if (superProperty === undefined || !(superProperty instanceof ComputedProperty)) { + /* + deprecate( + 'Calling `_super` when there is no computed on the parent class is deprecated.', + false, + { id: 'ember-metal.missing-super-computed', until: '3.0.0' } + ); + */ + console.warn('no super computed'); + return property; } @@ -129,6 +138,23 @@ function giveMethodSuper(obj, key, method, values, descs) { // Only wrap the new method if the original method was a function if (superMethod === undefined || 'function' !== typeof superMethod) { + /* + deprecate( + 'Calling `_super` when there is no method on the parent class is deprecated.', + false, + { id: 'ember-metal.missing-super-computed', until: '3.0.0' } + ); + * + */ + /* + deprecate( + 'Ember.required is deprecated as its behavior is inconsistent and unreliable.', + false, + { id: 'ember-metal.required', until: '3.0.0' } + ); + */ + console.warn('no super method'); + return method; } diff --git a/packages/ember-metal/tests/mixin/computed_test.js b/packages/ember-metal/tests/mixin/computed_test.js index 9a5ba71528c..b6a200841ca 100644 --- a/packages/ember-metal/tests/mixin/computed_test.js +++ b/packages/ember-metal/tests/mixin/computed_test.js @@ -141,3 +141,16 @@ QUnit.test('setter behavior works properly when overriding computed properties', equal(get(obj, 'cpWithoutSetter'), 'test', 'The default setter was called, the value is correct'); ok(!cpWasCalled, 'The default setter was called, not the CP itself'); }); + +QUnit.test('calling _super when there is no computed on parent class is deprecated', function() { + expectDeprecation('Calling `_super` when there is no computed on the parent class is deprecated.'); + + let SuperMixin = Mixin.create({}); + + let SubMixin = Mixin.create(SuperMixin, { + foo: computed({ + get(key) { return this._super(...arguments); }, + set(key, value) { return this._super(...arguments); } + }) + }); +}); diff --git a/packages/ember-metal/tests/mixin/method_test.js b/packages/ember-metal/tests/mixin/method_test.js index bd123de794b..f645864f837 100644 --- a/packages/ember-metal/tests/mixin/method_test.js +++ b/packages/ember-metal/tests/mixin/method_test.js @@ -154,6 +154,18 @@ QUnit.test('_super from a first-of-two mixins with no superclass function does n ok(true); }); +QUnit.test('calling _super when there is no method on parent class is deprecated', function() { + expectDeprecation('Calling `_super` when there is no method on the parent class is deprecated.'); + + let MixinA = Mixin.create({}); + + let MixinB = Mixin.create(MixinA, { + foo() { + this._super(...arguments); + } + }); +}); + // .......................................................... // CONFLICTS // From 21ca92d7d151368d9359dc562232dfc24b7665c2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Gast=C3=B3n=20I=2E=20Silva?= Date: Mon, 27 Mar 2017 23:39:26 -0700 Subject: [PATCH 2/4] invoke deprecate at the right moment --- packages/ember-metal/lib/mixin.js | 44 +++++++------------ .../ember-metal/tests/mixin/computed_test.js | 7 +-- .../ember-metal/tests/mixin/method_test.js | 8 +++- 3 files changed, 26 insertions(+), 33 deletions(-) diff --git a/packages/ember-metal/lib/mixin.js b/packages/ember-metal/lib/mixin.js index 77418887479..215ef0a90ab 100644 --- a/packages/ember-metal/lib/mixin.js +++ b/packages/ember-metal/lib/mixin.js @@ -95,16 +95,15 @@ function giveDescriptorSuper(meta, key, property, values, descs, base) { } if (superProperty === undefined || !(superProperty instanceof ComputedProperty)) { - /* - deprecate( - 'Calling `_super` when there is no computed on the parent class is deprecated.', - false, - { id: 'ember-metal.missing-super-computed', until: '3.0.0' } - ); - */ - console.warn('no super computed'); - - return property; + superProperty = { + _getter: function() { + deprecate( + `Calling \`_super\` when there is no computed \`${key}\` on the parent class is deprecated.`, + false, + { id: 'ember-metal.missing-super-computed', until: '3.0.0' } + ); + } + }; } // Since multiple mixins may inherit from the same parent, we need @@ -138,24 +137,13 @@ function giveMethodSuper(obj, key, method, values, descs) { // Only wrap the new method if the original method was a function if (superMethod === undefined || 'function' !== typeof superMethod) { - /* - deprecate( - 'Calling `_super` when there is no method on the parent class is deprecated.', - false, - { id: 'ember-metal.missing-super-computed', until: '3.0.0' } - ); - * - */ - /* - deprecate( - 'Ember.required is deprecated as its behavior is inconsistent and unreliable.', - false, - { id: 'ember-metal.required', until: '3.0.0' } - ); - */ - console.warn('no super method'); - - return method; + superMethod = function() { + deprecate( + `Calling \`_super\` when there is no method \`${key}\` on the parent class is deprecated.`, + false, + { id: 'ember-metal.missing-super-method', until: '3.0.0' } + ); + }; } return wrap(method, superMethod); diff --git a/packages/ember-metal/tests/mixin/computed_test.js b/packages/ember-metal/tests/mixin/computed_test.js index b6a200841ca..141011434ab 100644 --- a/packages/ember-metal/tests/mixin/computed_test.js +++ b/packages/ember-metal/tests/mixin/computed_test.js @@ -143,14 +143,15 @@ QUnit.test('setter behavior works properly when overriding computed properties', }); QUnit.test('calling _super when there is no computed on parent class is deprecated', function() { - expectDeprecation('Calling `_super` when there is no computed on the parent class is deprecated.'); + expectDeprecation('Calling `_super` when there is no computed `foo` on the parent class is deprecated.'); let SuperMixin = Mixin.create({}); let SubMixin = Mixin.create(SuperMixin, { foo: computed({ - get(key) { return this._super(...arguments); }, - set(key, value) { return this._super(...arguments); } + get(key) { return this._super(...arguments); } }) }); + + SubMixin.get('foo'); }); diff --git a/packages/ember-metal/tests/mixin/method_test.js b/packages/ember-metal/tests/mixin/method_test.js index f645864f837..e6167ace6e5 100644 --- a/packages/ember-metal/tests/mixin/method_test.js +++ b/packages/ember-metal/tests/mixin/method_test.js @@ -155,8 +155,6 @@ QUnit.test('_super from a first-of-two mixins with no superclass function does n }); QUnit.test('calling _super when there is no method on parent class is deprecated', function() { - expectDeprecation('Calling `_super` when there is no method on the parent class is deprecated.'); - let MixinA = Mixin.create({}); let MixinB = Mixin.create(MixinA, { @@ -164,6 +162,12 @@ QUnit.test('calling _super when there is no method on parent class is deprecated this._super(...arguments); } }); + + let obj = {}; + MixinB.apply(obj); + + expectDeprecation('Calling `_super` when there is no method `foo` on the parent class is deprecated.'); + obj.foo(); }); // .......................................................... From 5a2679fd85202d0b1d1e2eab87e059991a0413dd Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Gast=C3=B3n=20I=2E=20Silva?= Date: Mon, 27 Mar 2017 23:47:53 -0700 Subject: [PATCH 3/4] fix computed test --- packages/ember-metal/tests/mixin/computed_test.js | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/packages/ember-metal/tests/mixin/computed_test.js b/packages/ember-metal/tests/mixin/computed_test.js index 141011434ab..14c6e39d3e9 100644 --- a/packages/ember-metal/tests/mixin/computed_test.js +++ b/packages/ember-metal/tests/mixin/computed_test.js @@ -148,10 +148,12 @@ QUnit.test('calling _super when there is no computed on parent class is deprecat let SuperMixin = Mixin.create({}); let SubMixin = Mixin.create(SuperMixin, { - foo: computed({ - get(key) { return this._super(...arguments); } + foo: computed(function() { + return this._super(...arguments); }) }); - SubMixin.get('foo'); + let obj = {}; + SubMixin.apply(obj); + get(obj, 'foo'); }); From c299b89f8e31303dc29aa70e07926e7410f1c35a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Gast=C3=B3n=20I=2E=20Silva?= Date: Mon, 27 Mar 2017 23:58:02 -0700 Subject: [PATCH 4/4] fix mixin tests --- packages/ember-metal/tests/mixin/method_test.js | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/packages/ember-metal/tests/mixin/method_test.js b/packages/ember-metal/tests/mixin/method_test.js index e6167ace6e5..bd41437eb47 100644 --- a/packages/ember-metal/tests/mixin/method_test.js +++ b/packages/ember-metal/tests/mixin/method_test.js @@ -116,7 +116,8 @@ QUnit.test('Including the same mixin more than once will only run once', functio equal(cnt, 1, 'should invoke MixinA.foo one time'); }); -QUnit.test('_super from a single mixin with no superclass does not error', function() { +QUnit.test('_super from a single mixin with no superclass is deprecated', function() { + expectDeprecation('Calling `_super` when there is no method `foo` on the parent class is deprecated.'); let MixinA = Mixin.create({ foo() { this._super(...arguments); @@ -127,10 +128,11 @@ QUnit.test('_super from a single mixin with no superclass does not error', funct MixinA.apply(obj); obj.foo(); - ok(true); }); -QUnit.test('_super from a first-of-two mixins with no superclass function does not error', function() { +QUnit.test('_super from a first-of-two mixins with no superclass function is deprecated', function() { + expectDeprecation('Calling `_super` when there is no method `foo` on the parent class is deprecated.'); + // _super was previously calling itself in the second assertion. // Use remaining count of calls to ensure it doesn't loop indefinitely. let remaining = 3; @@ -155,6 +157,7 @@ QUnit.test('_super from a first-of-two mixins with no superclass function does n }); QUnit.test('calling _super when there is no method on parent class is deprecated', function() { + expectDeprecation('Calling `_super` when there is no method `foo` on the parent class is deprecated.'); let MixinA = Mixin.create({}); let MixinB = Mixin.create(MixinA, { @@ -166,7 +169,6 @@ QUnit.test('calling _super when there is no method on parent class is deprecated let obj = {}; MixinB.apply(obj); - expectDeprecation('Calling `_super` when there is no method `foo` on the parent class is deprecated.'); obj.foo(); });