File tree Expand file tree Collapse file tree 2 files changed +32
-5
lines changed
tests/integration/modifiers Expand file tree Collapse file tree 2 files changed +32
-5
lines changed Original file line number Diff line number Diff line change 1
1
import { setModifierManager , capabilities } from '@ember/modifier' ;
2
2
import { gte } from 'ember-compatibility-helpers' ;
3
+ import { untrack } from '@glimmer/validator' ;
3
4
4
5
/**
5
6
The `{{did-update}}` element modifier is activated when any of its arguments
@@ -80,17 +81,20 @@ export default setModifierManager(
80
81
} ,
81
82
82
83
updateModifier ( { element } , args ) {
84
+ let [ fn , ...positional ] = args . positional ;
85
+
83
86
if ( gte ( '3.22.0' ) ) {
84
87
// Consume individual properties to entangle tracking.
85
88
// https://github.com/emberjs/ember.js/issues/19277
86
89
// https://github.com/ember-modifier/ember-modifier/pull/63#issuecomment-815908201
87
90
args . positional . forEach ( ( ) => { } ) ;
88
91
args . named && Object . values ( args . named ) ;
92
+ untrack ( ( ) => {
93
+ fn ( element , positional , args . named ) ;
94
+ } ) ;
95
+ } else {
96
+ fn ( element , positional , args . named ) ;
89
97
}
90
-
91
- let [ fn , ...positional ] = args . positional ;
92
-
93
- fn ( element , positional , args . named ) ;
94
98
} ,
95
99
96
100
destroyModifier ( ) { } ,
Original file line number Diff line number Diff line change 1
1
import { module , test } from 'qunit' ;
2
+ import { tracked } from '@glimmer/tracking' ;
2
3
import { setupRenderingTest } from 'ember-qunit' ;
3
- import { render } from '@ember/test-helpers' ;
4
+ import { render , settled } from '@ember/test-helpers' ;
4
5
import hbs from 'htmlbars-inline-precompile' ;
5
6
6
7
module ( 'Integration | Modifier | did-update' , function ( hooks ) {
@@ -24,4 +25,26 @@ module('Integration | Modifier | did-update', function (hooks) {
24
25
25
26
this . set ( 'boundValue' , 'update' ) ;
26
27
} ) ;
28
+
29
+ test ( 'it consumes tracked properties without re-invoking' , async function ( assert ) {
30
+ class Context {
31
+ @tracked boundValue = 'initial' ;
32
+ @tracked secondaryValue = 'initial' ;
33
+ }
34
+
35
+ assert . expect ( 1 ) ;
36
+ this . context = new Context ( ) ;
37
+
38
+ this . someMethod = ( ) => {
39
+ // This assertion works as an assurance that we render before `secondaryValue` changes,
40
+ // and consumes its tag to ensure reading tracked properties won't re-trigger the modifier
41
+ assert . equal ( this . context . secondaryValue , 'initial' ) ;
42
+ } ;
43
+
44
+ await render ( hbs `<div {{did-update this.someMethod this.context.boundValue}}></div>` ) ;
45
+
46
+ this . context . boundValue = 'update' ;
47
+ await settled ( ) ;
48
+ this . context . secondaryValue = 'update' ;
49
+ } ) ;
27
50
} ) ;
You can’t perform that action at this time.
0 commit comments