Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We鈥檒l occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add deprecation for Route#disconnectOutlet #19407

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
@@ -1,5 +1,6 @@
import {
ApplicationTestCase,
expectDeprecation,
ModuleBasedTestResolver,
moduleFor,
strip,
Expand Down Expand Up @@ -225,7 +226,10 @@ if (ENV._DEBUG_RENDER_TREE) {
if (showHeader) {
this.render('header', { outlet: 'header' });
} else {
this.disconnectOutlet('header');
expectDeprecation(
() => this.disconnectOutlet('header'),
'The usage of `disconnectOutlet` is deprecated.'
);
}
}
}
Expand Down
9 changes: 9 additions & 0 deletions packages/@ember/-internals/routing/lib/system/route.ts
Expand Up @@ -1705,6 +1705,15 @@ class Route extends EmberObject implements IRoute {
@public
*/
disconnectOutlet(options: string | { outlet: string; parentView?: string }) {
deprecate('The usage of `disconnectOutlet` is deprecated.', false, {
id: 'route-disconnect-outlet',
until: '4.0.0',
url: 'https://deprecations.emberjs.com/v3.x/#toc_route-disconnect-outlet',
for: 'ember-source',
since: {
enabled: '3.27.0',
},
});
let outletName;
let parentView;
if (options) {
Expand Down
89 changes: 61 additions & 28 deletions packages/ember/tests/routing/template_rendering_test.js
Expand Up @@ -775,10 +775,14 @@ moduleFor(
});
},
hideModal() {
this.disconnectOutlet({
outlet: 'modal',
parentView: 'application',
});
expectDeprecation(
() =>
this.disconnectOutlet({
outlet: 'modal',
parentView: 'application',
}),
'The usage of `disconnectOutlet` is deprecated.'
);
},
},
})
Expand All @@ -794,7 +798,10 @@ moduleFor(
});
},
hideExtra() {
this.disconnectOutlet({ parentView: 'posts/index' });
expectDeprecation(
() => this.disconnectOutlet({ parentView: 'posts/index' }),
'The usage of `disconnectOutlet` is deprecated.'
);
},
},
})
Expand Down Expand Up @@ -898,7 +905,10 @@ moduleFor(
});
},
hideModal() {
this.disconnectOutlet('modal');
expectDeprecation(
() => this.disconnectOutlet('modal'),
'The usage of `disconnectOutlet` is deprecated.'
);
},
},
})
Expand Down Expand Up @@ -942,7 +952,7 @@ moduleFor(
}

['@test Route silently fails when cleaning an outlet from an inactive view'](assert) {
assert.expect(1); // handleURL
assert.expect(3); // handleURL

this.addTemplate('application', '{{outlet}}');
this.addTemplate('posts', "{{outlet 'modal'}}");
Expand All @@ -957,16 +967,23 @@ moduleFor(
Route.extend({
actions: {
hideSelf() {
this.disconnectOutlet({
outlet: 'main',
parentView: 'application',
});
expectDeprecation(
() =>
this.disconnectOutlet({
outlet: 'main',
parentView: 'application',
}),
'The usage of `disconnectOutlet` is deprecated.'
);
},
showModal() {
this.render('modal', { into: 'posts', outlet: 'modal' });
},
hideModal() {
this.disconnectOutlet({ outlet: 'modal', parentView: 'posts' });
expectDeprecation(
() => this.disconnectOutlet({ outlet: 'modal', parentView: 'posts' }),
'The usage of `disconnectOutlet` is deprecated.'
);
},
},
})
Expand Down Expand Up @@ -1080,10 +1097,14 @@ moduleFor(
},
actions: {
banish() {
this.disconnectOutlet({
parentView: 'application',
outlet: 'other',
});
expectDeprecation(
() =>
this.disconnectOutlet({
parentView: 'application',
outlet: 'other',
}),
'The usage of `disconnectOutlet` is deprecated.'
);
},
},
})
Expand Down Expand Up @@ -1249,10 +1270,14 @@ moduleFor(
});
},
close() {
this.disconnectOutlet({
outlet: 'modal',
parentView: 'application',
});
expectDeprecation(
() =>
this.disconnectOutlet({
outlet: 'modal',
parentView: 'application',
}),
'The usage of `disconnectOutlet` is deprecated.'
);
},
},
})
Expand Down Expand Up @@ -1329,10 +1354,14 @@ moduleFor(
Route.extend({
actions: {
close() {
this.disconnectOutlet({
parentView: 'application',
outlet: 'modal',
});
expectDeprecation(
() =>
this.disconnectOutlet({
parentView: 'application',
outlet: 'modal',
}),
'The usage of `disconnectOutlet` is deprecated.'
);
},
},
})
Expand Down Expand Up @@ -1438,10 +1467,14 @@ moduleFor(
});
},
hideModal() {
this.disconnectOutlet({
outlet: undefined,
parentView: 'application',
});
expectDeprecation(
() =>
this.disconnectOutlet({
outlet: undefined,
parentView: 'application',
}),
'The usage of `disconnectOutlet` is deprecated.'
);
},
},
})
Expand Down
6 changes: 6 additions & 0 deletions packages/internal-test-helpers/index.js
Expand Up @@ -7,6 +7,12 @@ export { default as moduleFor, setupTestClass } from './lib/module-for';
export { default as strip } from './lib/strip';
export { default as applyMixins } from './lib/apply-mixins';
export { default as getTextOf } from './lib/get-text-of';
export {
expectDeprecation,
expectNoDeprecation,
expectDeprecationAsync,
ignoreDeprecation,
} from './lib/ember-dev/deprecation';
export {
defineComponent,
defineSimpleHelper,
Expand Down
42 changes: 37 additions & 5 deletions packages/internal-test-helpers/lib/ember-dev/deprecation.ts
Expand Up @@ -25,17 +25,49 @@ export function setupDeprecationHelpers(hooks: NestedHooks, env: DebugEnv): void
});
}

export let expectDeprecation: DeprecationAssert['expectDeprecation'] = () => {
throw new Error(
'DeprecationAssert: To use `expectDeprecation` in a test you must call `setupDeprecationHelpers` first'
);
};

export let ignoreDeprecation: DeprecationAssert['ignoreDeprecation'] = () => {
throw new Error(
'DeprecationAssert: To use `ignoreDeprecation` in a test you must call `setupDeprecationHelpers` first'
);
};

export let expectDeprecationAsync: DeprecationAssert['expectDeprecationAsync'] = () => {
throw new Error(
'DeprecationAssert: To use `expectDeprecationAsync` in a test you must call `setupDeprecationHelpers` first'
);
};

export let expectNoDeprecation: DeprecationAssert['expectNoDeprecation'] = () => {
throw new Error(
'DeprecationAssert: To use `expectNoDeprecation` in a test you must call `setupDeprecationHelpers` first'
);
};

export let expectNoDeprecationAsync: DeprecationAssert['expectNoDeprecationAsync'] = () => {
throw new Error(
'DeprecationAssert: To use `expectNoDeprecationAsync` in a test you must call `setupDeprecationHelpers` first'
);
};

class DeprecationAssert extends DebugAssert {
constructor(env: DebugEnv) {
super('deprecate', env);
}

inject(): void {
window.expectNoDeprecation = this.expectNoDeprecation.bind(this);
window.expectNoDeprecationAsync = this.expectNoDeprecationAsync.bind(this);
window.expectDeprecation = this.expectDeprecation.bind(this);
window.expectDeprecationAsync = this.expectDeprecationAsync.bind(this);
window.ignoreDeprecation = this.ignoreDeprecation.bind(this);
window.expectNoDeprecation = expectNoDeprecation = this.expectNoDeprecation.bind(this);
window.expectNoDeprecationAsync = expectNoDeprecationAsync = this.expectNoDeprecationAsync.bind(
this
);
window.expectDeprecation = expectDeprecation = this.expectDeprecation.bind(this);
window.expectDeprecationAsync = expectDeprecationAsync = this.expectDeprecationAsync.bind(this);
window.ignoreDeprecation = ignoreDeprecation = this.ignoreDeprecation.bind(this);
super.inject();
}

Expand Down