File tree 2 files changed +39
-1
lines changed
2 files changed +39
-1
lines changed Original file line number Diff line number Diff line change 1
1
import { TaskFactory } from './task-factory' ;
2
2
3
3
function taskFromPropertyDescriptor (
4
- _target ,
4
+ target ,
5
5
key ,
6
6
descriptor ,
7
7
params = [ ] ,
@@ -23,6 +23,7 @@ function taskFromPropertyDescriptor(
23
23
let tasks = new WeakMap ( ) ;
24
24
let options = params [ 0 ] || { } ;
25
25
let factory = new factoryClass ( key , taskFn , options ) ;
26
+ factory . _setupEmberKVO ( target ) ;
26
27
27
28
return {
28
29
get ( ) {
Original file line number Diff line number Diff line change 1
1
import { module } from 'qunit' ;
2
2
import { run } from '@ember/runloop' ;
3
+ import EmberObject from '@ember/object' ;
3
4
import { setOwner } from '@ember/application' ;
4
5
import {
5
6
task ,
@@ -9,6 +10,7 @@ import {
9
10
enqueueTask ,
10
11
} from 'ember-concurrency' ;
11
12
import { decoratorTest } from '../helpers/helpers' ;
13
+ import { settled } from '@ember/test-helpers' ;
12
14
13
15
module ( 'Unit | decorators' , function ( ) {
14
16
decoratorTest ( 'Basic decorators functionality' , function ( assert ) {
@@ -86,4 +88,39 @@ module('Unit | decorators', function () {
86
88
} ) ;
87
89
assert . equal ( subject . encapsulated . last . value , 56 ) ;
88
90
} ) ;
91
+
92
+ decoratorTest (
93
+ '`observes` re-performs the task every time the observed property changes in a coalesced manner' ,
94
+ async function ( assert ) {
95
+ assert . expect ( 2 ) ;
96
+
97
+ let values = [ ] ;
98
+ class Obj extends EmberObject {
99
+ foo = 0 ;
100
+
101
+ @task ( { observes : 'foo' } )
102
+ * observingTask ( ) {
103
+ values . push ( this . foo ) ;
104
+ }
105
+ }
106
+
107
+ let obj = Obj . create ( ) ;
108
+ await settled ( ) ;
109
+
110
+ obj . set ( 'foo' , 1 ) ;
111
+ obj . set ( 'foo' , 2 ) ;
112
+ obj . set ( 'foo' , 3 ) ;
113
+ await settled ( ) ;
114
+
115
+ assert . deepEqual ( values , [ 3 ] ) ;
116
+ values = [ ] ;
117
+
118
+ obj . set ( 'foo' , 4 ) ;
119
+ obj . set ( 'foo' , 5 ) ;
120
+ obj . set ( 'foo' , 6 ) ;
121
+ await settled ( ) ;
122
+
123
+ assert . deepEqual ( values , [ 6 ] ) ;
124
+ }
125
+ ) ;
89
126
} ) ;
You can’t perform that action at this time.
0 commit comments