Skip to content

Commit 2a8bdd3

Browse files
committed
Added {{did-insert}} API docs
1 parent df97d70 commit 2a8bdd3

File tree

1 file changed

+44
-0
lines changed

1 file changed

+44
-0
lines changed

addon/modifiers/did-insert.js

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,49 @@
11
import Ember from 'ember';
22

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+
*/
347
export default Ember._setModifierManager(
448
() => ({
549
createModifier() {},

0 commit comments

Comments
 (0)