Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -204,6 +204,7 @@
"@ember/-internals/views/lib/mixins/action_support.js": "ember-source/@ember/-internals/views/lib/mixins/action_support.js",
"@ember/-internals/views/lib/system/event_dispatcher.js": "ember-source/@ember/-internals/views/lib/system/event_dispatcher.js",
"@ember/-internals/views/lib/system/utils.js": "ember-source/@ember/-internals/views/lib/system/utils.js",
"@ember/-internals/views/lib/views/core-view-utils.js": "ember-source/@ember/-internals/views/lib/views/core-view-utils.js",
"@ember/-internals/views/lib/views/core_view.js": "ember-source/@ember/-internals/views/lib/views/core_view.js",
"@ember/-internals/views/lib/views/states.js": "ember-source/@ember/-internals/views/lib/views/states.js",
"@ember/application/index.js": "ember-source/@ember/application/index.js",
Expand Down
9 changes: 8 additions & 1 deletion packages/@ember/-internals/deprecations/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ export function isRemoved(options: DeprecationOptions) {
return emberVersionGte(options.until);
}

interface DeprecationObject {
export interface DeprecationObject {
options: DeprecationOptions;
test: boolean;
isEnabled: boolean;
Expand Down Expand Up @@ -119,6 +119,13 @@ export const DEPRECATIONS = {
until: '7.5.0',
url: 'https://deprecations.emberjs.com/id/deprecate-comparable-mixin',
}),
DEPRECATE_EVENTED: deprecation({
id: 'deprecate-evented',
for: 'ember-source',
since: { available: '7.3.0' },
until: '8.0.0',
url: 'https://deprecations.emberjs.com/id/deprecate-evented',
}),
};

export function deprecateUntil(message: string, deprecation: DeprecationObject) {
Expand Down
27 changes: 14 additions & 13 deletions packages/@ember/-internals/glimmer/lib/component-managers/curly.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import {
setElementView,
setViewElement,
} from '@ember/-internals/views/lib/system/utils';
import { sendCoreViewEvent } from '@ember/-internals/views/lib/views/core-view-utils';
import type { Nullable } from '@ember/-internals/utility-types';
import { assert, debugFreeze } from '@ember/debug';
import { _instrumentStart } from '@ember/instrumentation';
Expand Down Expand Up @@ -318,20 +319,20 @@ export default class CurlyComponentManager
addChildView(parentView, component);
}

component.trigger('didReceiveAttrs');
sendCoreViewEvent(component, 'didReceiveAttrs');

let hasWrappedElement = component.tagName !== '';

// We usually do this in the `didCreateElement`, but that hook doesn't fire for tagless components
if (!hasWrappedElement) {
if (isInteractive) {
component.trigger('willRender');
sendCoreViewEvent(component, 'willRender');
}

component._transitionTo('hasElement');

if (isInteractive) {
component.trigger('willInsertElement');
sendCoreViewEvent(component, 'willInsertElement');
}
}

Expand All @@ -355,7 +356,7 @@ export default class CurlyComponentManager
}

if (isInteractive && hasWrappedElement) {
component.trigger('willRender');
sendCoreViewEvent(component, 'willRender');
}

endUntrackFrame();
Expand Down Expand Up @@ -420,7 +421,7 @@ export default class CurlyComponentManager

if (isInteractive) {
beginUntrackFrame();
component.trigger('willInsertElement');
sendCoreViewEvent(component, 'willInsertElement');
endUntrackFrame();
}
}
Expand All @@ -433,8 +434,8 @@ export default class CurlyComponentManager
didCreate({ component, isInteractive }: ComponentStateBucket): void {
if (isInteractive) {
component._transitionTo('inDOM');
component.trigger('didInsertElement');
component.trigger('didRender');
sendCoreViewEvent(component, 'didInsertElement');
sendCoreViewEvent(component, 'didRender');
}
}

Expand All @@ -456,13 +457,13 @@ export default class CurlyComponentManager
component.setProperties(props);
component[IS_DISPATCHING_ATTRS] = false;

component.trigger('didUpdateAttrs');
component.trigger('didReceiveAttrs');
sendCoreViewEvent(component, 'didUpdateAttrs');
sendCoreViewEvent(component, 'didReceiveAttrs');
}

if (isInteractive) {
component.trigger('willUpdate');
component.trigger('willRender');
sendCoreViewEvent(component, 'willUpdate');
sendCoreViewEvent(component, 'willRender');
}

endUntrackFrame();
Expand All @@ -477,8 +478,8 @@ export default class CurlyComponentManager

didUpdate({ component, isInteractive }: ComponentStateBucket): void {
if (isInteractive) {
component.trigger('didUpdate');
component.trigger('didRender');
sendCoreViewEvent(component, 'didUpdate');
sendCoreViewEvent(component, 'didRender');
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ import CurlyComponentManager, {
initialRenderInstrumentDetails,
processComponentInitializationAssertions,
} from './curly';
import { sendCoreViewEvent } from '@ember/-internals/views/lib/views/core-view-utils';

class RootComponentManager extends CurlyComponentManager {
component: Component;
Expand Down Expand Up @@ -48,13 +49,13 @@ class RootComponentManager extends CurlyComponentManager {
// We usually do this in the `didCreateElement`, but that hook doesn't fire for tagless components
if (!hasWrappedElement) {
if (isInteractive) {
component.trigger('willRender');
sendCoreViewEvent(component, 'willRender');
}

component._transitionTo('hasElement');

if (isInteractive) {
component.trigger('willInsertElement');
sendCoreViewEvent(component, 'willInsertElement');
}
}

Expand Down
3 changes: 2 additions & 1 deletion packages/@ember/-internals/glimmer/lib/renderer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import type { InternalOwner } from '@ember/-internals/owner';
import { getOwner } from '@ember/-internals/owner';
import { guidFor } from '@ember/-internals/utils/lib/guid';
import { getViewElement, getViewId } from '@ember/-internals/views/lib/system/utils';
import { sendCoreViewEvent } from '@ember/-internals/views/lib/views/core-view-utils';
import { assert } from '@ember/debug';
import {
associateDestroyableChild,
Expand Down Expand Up @@ -309,7 +310,7 @@ export class Renderer extends BaseRenderer {
this.cleanupRootFor(view);

if (this.state.isInteractive) {
view.trigger('didDestroyElement');
sendCoreViewEvent(view, 'didDestroyElement');
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import {
clearViewElement,
getViewElement,
} from '@ember/-internals/views/lib/system/utils';
import { sendCoreViewEvent } from '@ember/-internals/views/lib/views/core-view-utils';
import { registerDestructor } from '@glimmer/destroyable';
import type { CapturedNamedArguments } from '@glimmer/interfaces';
import type { Reference } from '@glimmer/reference/lib/reference';
Expand Down Expand Up @@ -52,8 +53,8 @@ export default class ComponentStateBucket {

if (isInteractive) {
beginUntrackFrame();
component.trigger('willDestroyElement');
component.trigger('willClearRender');
sendCoreViewEvent(component, 'willDestroyElement');
sendCoreViewEvent(component, 'willClearRender');
endUntrackFrame();

let element = getViewElement(component);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,12 @@
import { moduleFor, RenderingTestCase, strip, runTask } from 'internal-test-helpers';
import {
moduleFor,
RenderingTestCase,
strip,
runTask,
expectDeprecation,
testUnless,
} from 'internal-test-helpers';
import { DEPRECATIONS } from '../../../../deprecations';

import { set } from '@ember/object';
import { setComponentTemplate } from '@glimmer/manager';
Expand Down Expand Up @@ -39,7 +47,9 @@ class AbstractAppendTest extends RenderingTestCase {
this.ids.push(component.elementId);
}

[`@test (new) lifecycle hooks during component append`](assert) {
[`${testUnless(DEPRECATIONS.DEPRECATE_EVENTED.isRemoved)} @test (new) lifecycle hooks during component append`](
assert
) {
let hooks = [];

let componentsByName = {};
Expand All @@ -57,7 +67,13 @@ class AbstractAppendTest extends RenderingTestCase {
}
componentsByName[name] = this;
pushHook('init');
this.on('init', () => pushHook('on(init)'));
expectDeprecation(
() => {
this.on('init', () => pushHook('on(init)'));
},
/Evented#on` is deprecated/,
DEPRECATIONS.DEPRECATE_EVENTED.isEnabled
);
}

didReceiveAttrs() {
Expand Down Expand Up @@ -279,7 +295,9 @@ class AbstractAppendTest extends RenderingTestCase {
);
}

[`@test lifecycle hooks during component append`](assert) {
[`${testUnless(DEPRECATIONS.DEPRECATE_EVENTED.isRemoved)} @test lifecycle hooks during component append`](
assert
) {
let hooks = [];

let componentsByName = {};
Expand All @@ -298,7 +316,13 @@ class AbstractAppendTest extends RenderingTestCase {
}
componentsByName[name] = this;
pushHook('init');
this.on('init', () => pushHook('on(init)'));
expectDeprecation(
() => {
this.on('init', () => pushHook('on(init)'));
},
/Evented#on` is deprecated/,
DEPRECATIONS.DEPRECATE_EVENTED.isEnabled
);
}

didReceiveAttrs() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,10 @@ import {
equalsElement,
runTask,
runLoopSettled,
expectDeprecation,
testUnless,
} from 'internal-test-helpers';
import { DEPRECATIONS } from '../../../../deprecations';

import { action } from '@ember/object';
import { run } from '@ember/runloop';
Expand Down Expand Up @@ -3440,48 +3443,60 @@ moduleFor(
runTask(() => set(this.context, 'foo', 5));
}

['@test triggering an event only attempts to invoke an identically named method, if it actually is a function (GH#15228)'](
[`${testUnless(DEPRECATIONS.DEPRECATE_EVENTED.isRemoved)} @test triggering an event only attempts to invoke an identically named method, if it actually is a function (GH#15228)`](
assert
) {
assert.expect(3);
assert.expect(5);

let payload = ['arbitrary', 'event', 'data'];

this.owner.register(
'component:evented-component',
Component.extend({
someTruthyProperty: true,

init() {
this._super(...arguments);
this.trigger('someMethod', ...payload);
this.trigger('someTruthyProperty', ...payload);
},
expectDeprecation(
() => {
this.owner.register(
'component:evented-component',
Component.extend({
someTruthyProperty: true,

init() {
this._super(...arguments);
expectDeprecation(
() => {
this.trigger('someMethod', ...payload);
this.trigger('someTruthyProperty', ...payload);
},
/Evented#trigger` is deprecated/,
DEPRECATIONS.DEPRECATE_EVENTED.isEnabled
);
},

someMethod(...data) {
assert.deepEqual(
data,
payload,
'the method `someMethod` should be called, when `someMethod` is triggered'
);
},
someMethod(...data) {
assert.deepEqual(
data,
payload,
'the method `someMethod` should be called, when `someMethod` is triggered'
);
},

listenerForSomeMethod: on('someMethod', function (...data) {
assert.deepEqual(
data,
payload,
'the listener `listenerForSomeMethod` should be called, when `someMethod` is triggered'
);
}),

listenerForSomeTruthyProperty: on('someTruthyProperty', function (...data) {
assert.deepEqual(
data,
payload,
'the listener `listenerForSomeTruthyProperty` should be called, when `someTruthyProperty` is triggered'
);
}),
})
listenerForSomeMethod: on('someMethod', function (...data) {
assert.deepEqual(
data,
payload,
'the listener `listenerForSomeMethod` should be called, when `someMethod` is triggered'
);
}),

listenerForSomeTruthyProperty: on('someTruthyProperty', function (...data) {
assert.deepEqual(
data,
payload,
'the listener `listenerForSomeTruthyProperty` should be called, when `someTruthyProperty` is triggered'
);
}),
})
);
},
/`on\(\)` event decorator is deprecated/,
DEPRECATIONS.DEPRECATE_EVENTED.isEnabled
);

this.render(`{{evented-component}}`);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import { precompileTemplate } from '@ember/template-compilation';
import { setComponentTemplate } from '@glimmer/manager';

import { Component } from '../../utils/helpers';
import { addListener } from '@ember/-internals/metal';

class LifeCycleHooksTest extends RenderingTestCase {
constructor() {
Expand Down Expand Up @@ -176,7 +177,7 @@ class LifeCycleHooksTest extends RenderingTestCase {
assertNoElement('init', this);
assertState('init', 'preRender', this);

this.on('init', () => pushHook('on(init)'));
addListener(this, 'init', () => pushHook('on(init)'));

schedule('afterRender', () => {
this.isInitialRender = false;
Expand Down
Loading
Loading