-
Notifications
You must be signed in to change notification settings - Fork 92
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Bug: stop watching unless viewportSpy=true is passed to modifier (#270)
* Bug: stop watching unless viewportSpy=true is passed to modifier * mv around * fix teset * fixup modifer case * fxi lint * add test * fix name * beef up README
- Loading branch information
Showing
9 changed files
with
138 additions
and
88 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,23 +1,35 @@ | ||
import Component from '@glimmer/component'; | ||
import { action, set } from '@ember/object'; | ||
import InViewportMixin from 'ember-in-viewport'; | ||
import { action } from '@ember/object'; | ||
import { inject as service } from '@ember/service'; | ||
|
||
export default class MyModifier extends Component { | ||
@service inViewport; | ||
|
||
export default class MyModifier extends Component.extend(InViewportMixin) { | ||
@action | ||
setupInViewport(element) { | ||
this.watchElement(element); | ||
const viewportSpy = true; | ||
const viewportTolerance = { | ||
bottom: 300, | ||
}; | ||
const { onEnter } = this.inViewport.watchElement(element, { | ||
viewportSpy, | ||
viewportTolerance, | ||
}); | ||
onEnter(this.didEnterViewport.bind(this)); | ||
} | ||
|
||
constructor() { | ||
super(...arguments); | ||
|
||
set(this, 'viewportSpy', true); | ||
set(this, 'viewportTolerance', { | ||
bottom: 300, | ||
}); | ||
} | ||
|
||
didEnterViewport() { | ||
this.infinityLoad(); | ||
this.args.infinityLoad(); | ||
} | ||
|
||
willDestroy() { | ||
super.willDestroy(...arguments); | ||
|
||
const loader = document.getElementById('loader'); | ||
this.inViewport.stopWatching(loader); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,46 +1,37 @@ | ||
import Controller from '@ember/controller'; | ||
import { set, action } from '@ember/object'; | ||
import { later } from '@ember/runloop'; | ||
import { Promise } from 'rsvp'; | ||
import { action, set } from '@ember/object'; | ||
|
||
const images = ['jarjan', 'aio___', 'kushsolitary', 'kolage', 'idiot', 'gt']; | ||
let rect = | ||
'<rect x="10" y="10" width="30" height="30" stroke="black" fill="transparent" stroke-width="5"/>'; | ||
let circle = | ||
'<circle cx="25" cy="75" r="20" stroke="red" fill="transparent" stroke-width="5"/>'; | ||
let line = | ||
'<line x1="10" x2="50" y1="110" y2="150" stroke="orange" stroke-width="5"/>'; | ||
|
||
const images = [rect, circle, line]; | ||
const arr = Array.apply(null, Array(10)); | ||
const models = [ | ||
...arr.map(() => { | ||
return { | ||
bgColor: 'E8D26F', | ||
url: `https://s3.amazonaws.com/uifaces/faces/twitter/${ | ||
images[(Math.random() * images.length) | 0] | ||
}/128.jpg`, | ||
}; | ||
}), | ||
...arr.map(() => `${images[(Math.random() * images.length) | 0]}`), | ||
]; | ||
|
||
export default class InfinityModifier extends Controller { | ||
constructor() { | ||
super(...arguments); | ||
this.viewportToleranceOverride = { | ||
bottom: 200, | ||
}; | ||
} | ||
|
||
models = models; | ||
|
||
@action | ||
infinityLoad() { | ||
const arr = Array.apply(null, Array(10)); | ||
const newModels = [ | ||
...arr.map(() => { | ||
return { | ||
bgColor: '0790EB', | ||
url: `https://s3.amazonaws.com/uifaces/faces/twitter/${ | ||
images[(Math.random() * images.length) | 0] | ||
}/128.jpg`, | ||
}; | ||
}), | ||
...arr.map(() => `${images[(Math.random() * images.length) | 0]}`), | ||
]; | ||
|
||
return new Promise((resolve) => { | ||
later(() => { | ||
const models = this.models; | ||
models.push(...newModels); | ||
set(this, 'models', Array.prototype.slice.call(models)); | ||
resolve(); | ||
}, 0); | ||
}); | ||
const models = this.models; | ||
models.push(...newModels); | ||
set(this, 'models', Array.prototype.slice.call(models)); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters