Skip to content

Commit 220c6d0

Browse files
committedJun 25, 2021
Demo the isObserving functionality
1 parent a70d1cd commit 220c6d0

File tree

3 files changed

+43
-8
lines changed

3 files changed

+43
-8
lines changed
 

‎tests/dummy/app/controllers/index.js

+16
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,12 @@ export default class IndexController extends Controller {
1111

1212
maxIntersections = 5;
1313

14+
@tracked
15+
isObserving = true;
16+
17+
@tracked
18+
numIntersectionsWithIsObserving = 0;
19+
1420
@tracked
1521
shouldScrollIntoView = false;
1622

@@ -24,6 +30,16 @@ export default class IndexController extends Controller {
2430
this.numIntersectionsWithMaxEnter++;
2531
}
2632

33+
@action
34+
toggleIsObserving() {
35+
this.isObserving = !this.isObserving;
36+
}
37+
38+
@action
39+
onEnteringWithIsObserving() {
40+
this.numIntersectionsWithIsObserving++;
41+
}
42+
2743
@action
2844
onScrollIntoViewTrigger() {
2945
this.shouldScrollIntoView = true;

‎tests/dummy/app/styles/app.scss

+7-7
Original file line numberDiff line numberDiff line change
@@ -9,17 +9,17 @@
99
}
1010
}
1111

12+
.action-button {
13+
border-radius: 4px;
14+
padding: 0.5em;
15+
background-color: orangered;
16+
color: white;
17+
}
18+
1219
.scroll-into-view {
1320
border: 1px dotted black;
1421
padding: 50px 16px;
1522
text-align: center;
16-
17-
button {
18-
border-radius: 4px;
19-
padding: .5em;
20-
background-color: orangered;
21-
color: white;
22-
}
2323
}
2424

2525
// prevent copy button from overlapping code

‎tests/dummy/app/templates/index.hbs

+20-1
Original file line numberDiff line numberDiff line change
@@ -24,12 +24,31 @@
2424
</demo.example>
2525
{{demo.snippet "did-intersect-with-max-enter.hbs" label="example with max enter.hbs"}}
2626

27+
<demo.example @name="did-intersect-with-is-observing.hbs">
28+
<div
29+
class="intersection-box"
30+
{{did-intersect
31+
isObserving=this.isObserving
32+
onEnter=this.onEnteringWithIsObserving
33+
}}
34+
>
35+
<p>Number of times this box has intersected the screen: {{this.numIntersectionsWithIsObserving}}</p>
36+
37+
<p>isObserving: {{this.isObserving}}</p>
38+
39+
<button type='button' class="action-button" {{on "click" this.toggleIsObserving}}>
40+
{{if this.isObserving "Stop" "Start"}} observing
41+
</button>
42+
</div>
43+
</demo.example>
44+
{{demo.snippet "did-intersect-with-is-observing.hbs" label="example with isObserving.hbs"}}
45+
2746
<demo.example @name="scroll-into-view.hbs">
2847
<div
2948
class="scroll-into-view"
3049
{{scroll-into-view shouldScroll=this.shouldScrollIntoView}}
3150
>
32-
<button type="button" class="scroll-into-view__button" {{on "click" this.onScrollIntoViewTrigger}}>
51+
<button type="button" class="action-button" {{on "click" this.onScrollIntoViewTrigger}}>
3352
Trigger Scroll-into-view on click
3453
</button>
3554
</div>

0 commit comments

Comments
 (0)