File tree Expand file tree Collapse file tree 2 files changed +45
-16
lines changed Expand file tree Collapse file tree 2 files changed +45
-16
lines changed Original file line number Diff line number Diff line change 1+ import type { DeprecationOptions } from '@ember/debug' ;
2+ import type Mixin from '@ember/object/mixin' ;
3+
4+ /** @internal */
5+ export const DEPRECATION = Symbol ( 'DEPRECATION' ) ;
6+
7+ /** @internal */
8+ export function setDeprecation (
9+ mixin : Mixin ,
10+ value : { message : string ; options : DeprecationOptions } | null
11+ ) {
12+ mixin [ DEPRECATION ] = value ;
13+ }
14+
15+ let deprecationsEnabled = true ;
16+
17+ export function findDeprecation (
18+ mixin : Mixin
19+ ) : { message : string ; options : DeprecationOptions } | null {
20+ if ( ! deprecationsEnabled ) {
21+ return null ;
22+ }
23+ if ( mixin [ DEPRECATION ] ) {
24+ return mixin [ DEPRECATION ] ;
25+ }
26+ for ( let childMixin of mixin . mixins ?? [ ] ) {
27+ let deprecation = findDeprecation ( childMixin ) ;
28+ if ( deprecation ) {
29+ return deprecation ;
30+ }
31+ }
32+ return null ;
33+ }
34+
35+ export function disableDeprecations < T > ( callback : ( ) => T ) : T {
36+ try {
37+ deprecationsEnabled = false ;
38+ return callback ( ) ;
39+ } finally {
40+ deprecationsEnabled = true ;
41+ }
42+ }
Original file line number Diff line number Diff line change @@ -29,6 +29,7 @@ import {
2929 defineDecorator ,
3030 defineValue ,
3131} from '@ember/-internals/metal' ;
32+ import { DEPRECATION , findDeprecation } from '@ember/-internals/utils/lib/mixin-deprecation' ;
3233
3334const a_concat = Array . prototype . concat ;
3435const { isArray } = Array ;
@@ -545,21 +546,7 @@ export default class Mixin {
545546 properties : { [ key : string ] : any } | undefined ;
546547
547548 /*** @internal */
548- deprecation : { message : string ; options : DeprecationOptions } | undefined ;
549-
550- /** @internal */
551- findDeprecation ( ) : { message : string ; options : DeprecationOptions } | null {
552- if ( this . deprecation ) {
553- return this . deprecation ;
554- }
555- for ( let mixin of this . mixins ?? [ ] ) {
556- let deprecation = mixin . findDeprecation ( ) ;
557- if ( deprecation ) {
558- return deprecation ;
559- }
560- }
561- return null ;
562- }
549+ [ DEPRECATION ] : { message : string ; options : DeprecationOptions } | null = null ;
563550
564551 /** @internal */
565552 ownerConstructor : any ;
@@ -641,7 +628,7 @@ export default class Mixin {
641628
642629 if ( DEBUG ) {
643630 for ( let mixin of args ) {
644- let deprecation = mixin instanceof Mixin ? mixin . findDeprecation ( ) : null ;
631+ let deprecation = mixin instanceof Mixin ? findDeprecation ( mixin ) : null ;
645632 deprecate ( deprecation ?. message ?? 'Huh???' , ! deprecation , deprecation ?. options ) ;
646633 }
647634 }
You can’t perform that action at this time.
0 commit comments