@@ -3,37 +3,35 @@ import { addObserver } from '@ember/object/observers';
3
3
import { addListener } from '@ember/object/events' ;
4
4
import EmberObject from '@ember/object' ;
5
5
import { getOwner } from '@ember/application' ;
6
- import {
7
- default as TaskInstance ,
8
- getRunningInstance
9
- } from './-task-instance' ;
6
+ import { default as TaskInstance , getRunningInstance } from './-task-instance' ;
10
7
import {
11
8
PERFORM_TYPE_DEFAULT ,
12
9
PERFORM_TYPE_UNLINKED ,
13
- PERFORM_TYPE_LINKED
10
+ PERFORM_TYPE_LINKED ,
14
11
} from './-task-instance' ;
15
12
import TaskStateMixin from './-task-state-mixin' ;
16
- import { TaskGroup } from './-task-group' ;
17
- import {
18
- propertyModifiers ,
19
- resolveScheduler
20
- } from './-property-modifiers-mixin' ;
13
+ import { propertyModifiers } from './-property-modifiers-mixin' ;
21
14
import {
22
15
objectAssign ,
23
16
INVOKE ,
24
17
_cleanupOnDestroy ,
25
- _ComputedProperty
18
+ _ComputedProperty ,
26
19
} from './utils' ;
27
20
import EncapsulatedTask from './-encapsulated-task' ;
28
21
import { deprecate } from '@ember/debug' ;
22
+ import { gte } from 'ember-compatibility-helpers' ;
29
23
30
24
const PerformProxy = EmberObject . extend ( {
31
25
_task : null ,
32
26
_performType : null ,
33
27
_linkedObject : null ,
34
28
35
29
perform ( ...args ) {
36
- return this . _task . _performShared ( args , this . _performType , this . _linkedObject ) ;
30
+ return this . _task . _performShared (
31
+ args ,
32
+ this . _performType ,
33
+ this . _linkedObject
34
+ ) ;
37
35
} ,
38
36
} ) ;
39
37
@@ -184,10 +182,15 @@ export const Task = EmberObject.extend(TaskStateMixin, {
184
182
if ( typeof this . fn === 'object' ) {
185
183
let owner = getOwner ( this . context ) ;
186
184
let ownerInjection = owner ? owner . ownerInjection ( ) : { } ;
187
- this . _taskInstanceFactory = EncapsulatedTask . extend ( ownerInjection , this . fn ) ;
185
+ this . _taskInstanceFactory = EncapsulatedTask . extend (
186
+ ownerInjection ,
187
+ this . fn
188
+ ) ;
188
189
}
189
190
190
- _cleanupOnDestroy ( this . context , this , 'cancelAll' , { reason : 'the object it lives on was destroyed or unrendered' } ) ;
191
+ _cleanupOnDestroy ( this . context , this , 'cancelAll' , {
192
+ reason : 'the object it lives on was destroyed or unrendered' ,
193
+ } ) ;
191
194
} ,
192
195
193
196
_curry ( ...args ) {
@@ -315,7 +318,6 @@ export const Task = EmberObject.extend(TaskStateMixin, {
315
318
* @readOnly
316
319
*/
317
320
318
-
319
321
/**
320
322
* The current number of active running task instances. This
321
323
* number will never exceed maxConcurrency.
@@ -413,42 +415,56 @@ export const Task = EmberObject.extend(TaskStateMixin, {
413
415
414
416
@class TaskProperty
415
417
*/
416
- export class TaskProperty extends _ComputedProperty {
417
- constructor ( taskFn ) {
418
- let tp ;
419
- super ( function ( _propertyName ) {
420
- taskFn . displayName = `${ _propertyName } (task)` ;
421
- return Task . create ( {
422
- fn : tp . taskFn ,
423
- context : this ,
424
- _origin : this ,
425
- _taskGroupPath : tp . _taskGroupPath ,
426
- _scheduler : resolveScheduler ( tp , this , TaskGroup ) ,
427
- _propertyName,
428
- _debug : tp . _debug ,
429
- _hasEnabledEvents : tp . _hasEnabledEvents
430
- } ) ;
431
- } ) ;
432
- tp = this ;
433
- this . taskFn = taskFn ;
434
- this . eventNames = null ;
435
- this . cancelEventNames = null ;
436
- this . _observes = null ;
437
- }
418
+ export let TaskProperty ;
419
+
420
+ if ( gte ( '3.10.0' ) ) {
421
+ TaskProperty = class { } ;
422
+ } else {
423
+ // Prior to the 3.10.0 refactors, we had to extend the _ComputedProprety class
424
+ // for a classic decorator/descriptor to run correctly.
425
+ TaskProperty = class extends _ComputedProperty { } ;
426
+ }
438
427
428
+ objectAssign ( TaskProperty . prototype , {
439
429
setup ( proto , taskName ) {
440
430
if ( super . setup ) {
441
431
super . setup ( ...arguments ) ;
442
432
}
433
+
443
434
if ( this . _maxConcurrency !== Infinity && ! this . _hasSetBufferPolicy ) {
444
435
// eslint-disable-next-line no-console
445
- console . warn ( `The use of maxConcurrency() without a specified task modifier is deprecated and won't be supported in future versions of ember-concurrency. Please specify a task modifier instead, e.g. \`${ taskName } : task(...).enqueue().maxConcurrency(${ this . _maxConcurrency } )\`` ) ;
436
+ console . warn (
437
+ `The use of maxConcurrency() without a specified task modifier is deprecated and won't be supported in future versions of ember-concurrency. Please specify a task modifier instead, e.g. \`${ taskName } : task(...).enqueue().maxConcurrency(${
438
+ this . _maxConcurrency
439
+ } )\``
440
+ ) ;
446
441
}
447
442
448
- registerOnPrototype ( addListener , proto , this . eventNames , taskName , 'perform' , false ) ;
449
- registerOnPrototype ( addListener , proto , this . cancelEventNames , taskName , 'cancelAll' , false ) ;
450
- registerOnPrototype ( addObserver , proto , this . _observes , taskName , 'perform' , true ) ;
451
- }
443
+ registerOnPrototype (
444
+ addListener ,
445
+ proto ,
446
+ this . eventNames ,
447
+ taskName ,
448
+ 'perform' ,
449
+ false
450
+ ) ;
451
+ registerOnPrototype (
452
+ addListener ,
453
+ proto ,
454
+ this . cancelEventNames ,
455
+ taskName ,
456
+ 'cancelAll' ,
457
+ false
458
+ ) ;
459
+ registerOnPrototype (
460
+ addObserver ,
461
+ proto ,
462
+ this . _observes ,
463
+ taskName ,
464
+ 'perform' ,
465
+ true
466
+ ) ;
467
+ } ,
452
468
453
469
/**
454
470
* Calling `task(...).on(eventName)` configures the task to be
@@ -485,7 +501,7 @@ export class TaskProperty extends _ComputedProperty {
485
501
this . eventNames = this . eventNames || [ ] ;
486
502
this . eventNames . push . apply ( this . eventNames , arguments ) ;
487
503
return this ;
488
- }
504
+ } ,
489
505
490
506
/**
491
507
* This behaves like the {@linkcode TaskProperty#on task(...).on() modifier},
@@ -503,12 +519,12 @@ export class TaskProperty extends _ComputedProperty {
503
519
this . cancelEventNames = this . cancelEventNames || [ ] ;
504
520
this . cancelEventNames . push . apply ( this . cancelEventNames , arguments ) ;
505
521
return this ;
506
- }
522
+ } ,
507
523
508
524
observes ( ...properties ) {
509
525
this . _observes = properties ;
510
526
return this ;
511
- }
527
+ } ,
512
528
513
529
/**
514
530
* Configures the task to cancel old currently task instances
@@ -630,25 +646,34 @@ export class TaskProperty extends _ComputedProperty {
630
646
*/
631
647
632
648
perform ( ) {
633
- deprecate ( `[DEPRECATED] An ember-concurrency task property was not set on its object via 'defineProperty'.
634
- You probably used 'set(obj, "myTask", task(function* () { ... }) )'.
649
+ deprecate (
650
+ `[DEPRECATED] An ember-concurrency task property was not set on its object via 'defineProperty'.
651
+ You probably used 'set(obj, "myTask", task(function* () { ... }) )'.
635
652
Unfortunately due to this we can't tell you the name of the task.` ,
636
653
false ,
637
654
{
638
655
id : 'ember-meta.descriptor-on-object' ,
639
656
until : '3.5.0' ,
640
- url : 'https://emberjs.com/deprecations/v3.x#toc_use-defineProperty-to-define-computed-properties' ,
657
+ url :
658
+ 'https://emberjs.com/deprecations/v3.x#toc_use-defineProperty-to-define-computed-properties' ,
641
659
}
642
660
) ;
643
- throw new Error ( "An ember-concurrency task property was not set on its object via 'defineProperty'. See deprecation warning for details." ) ;
644
- }
645
- }
661
+ throw new Error (
662
+ "An ember-concurrency task property was not set on its object via 'defineProperty'. See deprecation warning for details."
663
+ ) ;
664
+ } ,
665
+ } ) ;
646
666
647
667
objectAssign ( TaskProperty . prototype , propertyModifiers ) ;
648
668
649
- let handlerCounter = 0 ;
650
-
651
- function registerOnPrototype ( addListenerOrObserver , proto , names , taskName , taskMethod , once ) {
669
+ function registerOnPrototype (
670
+ addListenerOrObserver ,
671
+ proto ,
672
+ names ,
673
+ taskName ,
674
+ taskMethod ,
675
+ once
676
+ ) {
652
677
if ( names ) {
653
678
for ( let i = 0 ; i < names . length ; ++ i ) {
654
679
let name = names [ i ] ;
@@ -671,3 +696,5 @@ function makeTaskCallback(taskName, method, once) {
671
696
}
672
697
} ;
673
698
}
699
+
700
+ let handlerCounter = 0 ;
0 commit comments