File tree Expand file tree Collapse file tree 3 files changed +122
-0
lines changed Expand file tree Collapse file tree 3 files changed +122
-0
lines changed Original file line number Diff line number Diff line change 1
1
import Ember from 'ember' ;
2
2
3
+ /**
4
+ The `{{did-insert}}` element modifier is activated when an element is
5
+ inserted into the DOM.
6
+
7
+ In this example, the `fadeIn` function receives the `div` DOM element as its
8
+ first argument and is executed after the element is inserted into the DOM.
9
+
10
+ ```handlebars
11
+ <div {{did-insert this.fadeIn}} class="alert">
12
+ {{yield}}
13
+ </div>
14
+ ```
15
+
16
+ ```js
17
+ export default Component.extend({
18
+ fadeIn(element) {
19
+ element.classList.add('fade-in');
20
+ }
21
+ });
22
+ ```
23
+
24
+ By default, the executed function will be unbound. If you would like to access
25
+ the component context in your function, use the `action` helper as follows:
26
+
27
+ ```handlebars
28
+ <div {{did-insert (action this.incrementCount)}}>first</div>
29
+ <div {{did-insert (action this.incrementCount)}}>second</div>
30
+
31
+ <p>{{this.count}} elements were rendered</p>
32
+ ```
33
+
34
+ ```js
35
+ export default Component.extend({
36
+ @tracked count = 0;
37
+
38
+ incrementCount() {
39
+ this.count++;
40
+ }
41
+ });
42
+ ```
43
+
44
+ @method did-insert
45
+ @public
46
+ */
3
47
export default Ember . _setModifierManager (
4
48
( ) => ( {
5
49
createModifier ( ) { } ,
Original file line number Diff line number Diff line change 1
1
import Ember from 'ember' ;
2
2
3
+ /**
4
+ The `{{did-update}}` element modifier is activated when any of its arguments
5
+ are updated. It does not run on initial render.
6
+
7
+ In this example, the `resize` function receives the `textarea` DOM element as its
8
+ first argument and is executed anytime the `@text` argument changes.
9
+
10
+ ```handlebars
11
+ <textarea {{did-update this.resize @text }} readonly style="padding: 0px;">
12
+ {{@text }}
13
+ </textarea>
14
+ ```
15
+
16
+ ```js
17
+ export default Component.extend({
18
+ resize(element) {
19
+ element.style.height = `${element.scrollHeight}px`;
20
+ }
21
+ });
22
+ ```
23
+
24
+ In addition to the `element`, both named and positional arguments are passed to the
25
+ executed function:
26
+
27
+ ```handlebars
28
+ <div {{did-update this.logArguments @first @second third=@third}} />
29
+ ```
30
+
31
+ ```js
32
+ export default Component.extend({
33
+ logArguments(element, [first, second], { third }) {
34
+ console.log('element', element);
35
+ console.log('positional args', first, second);
36
+ console.log('names args', third);
37
+ }
38
+ });
39
+ ```
40
+
41
+ By default, the executed function will be unbound. If you would like to access
42
+ the component context in your function, use the `action` helper as follows:
43
+
44
+ ```handlebars
45
+ <div {{did-update (action this.someFunction) @someArg } />
46
+ ```
47
+
48
+ @method did-update
49
+ @public
50
+ */
3
51
export default Ember . _setModifierManager (
4
52
( ) => ( {
5
53
createModifier ( ) {
Original file line number Diff line number Diff line change 1
1
import Ember from 'ember' ;
2
2
3
+ /**
4
+ The `{{will-destroy}}` element modifier is activated immediately before the element
5
+ is removed from the DOM.
6
+
7
+ ```handlebars
8
+ <div {{will-destroy this.teardownPlugin}}>
9
+ {{yield}}
10
+ </div>
11
+ ```
12
+
13
+ ```js
14
+ export default Component.extend({
15
+ teardownPlugin(element) {
16
+ // teardown logic here
17
+ }
18
+ });
19
+ ```
20
+
21
+ By default, the executed function will be unbound. If you would like to access
22
+ the component context in your function, use the `action` helper as follows:
23
+
24
+ ```handlebars
25
+ <div {{will-destroy (action this.teardownPlugin)}}>
26
+ {{yield}}
27
+ </div>
28
+ ```
29
+
30
+ @method will-destroy
31
+ @public
32
+ */
3
33
export default Ember . _setModifierManager (
4
34
( ) => ( {
5
35
createModifier ( ) {
You can’t perform that action at this time.
0 commit comments