-
-
Notifications
You must be signed in to change notification settings - Fork 18
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #1 from dhilt/observable
Workflow + Clipping process refactoring
- Loading branch information
Showing
13 changed files
with
474 additions
and
308 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
let timer = null; | ||
let next = null; | ||
|
||
const runTimer = (delay) => { | ||
timer = setTimeout(() => { | ||
timer = null; | ||
if(next) { | ||
next(); | ||
next = null; | ||
runTimer(delay); | ||
} | ||
}, delay) | ||
}; | ||
|
||
const debouncedRound = (cb, delay) => { | ||
if(!timer) { | ||
cb(); | ||
} | ||
else { | ||
next = cb; | ||
clearTimeout(timer); | ||
} | ||
runTimer(delay); | ||
}; | ||
|
||
export default debouncedRound |
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 was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
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,41 +1,48 @@ | ||
import {Component, OnInit, Input} from '@angular/core'; | ||
import {ContentChild, TemplateRef, ElementRef, Renderer} from '@angular/core'; | ||
import {Component, ChangeDetectionStrategy, ChangeDetectorRef, OnInit, OnDestroy, Input} from '@angular/core'; | ||
import {ContentChild, TemplateRef, ElementRef, Renderer2} from '@angular/core'; | ||
import {HostListener} from '@angular/core'; | ||
|
||
import {Observable} from 'rxjs/Observable'; | ||
import {Subject} from 'rxjs/Subject'; | ||
import {AsyncSubject} from 'rxjs/AsyncSubject'; | ||
|
||
import Process from './processes/index'; | ||
import Workflow from './workflow'; | ||
import Elements from './elements'; | ||
import Data from './data'; | ||
import Direction from './direction'; | ||
|
||
import debouncedRound from './debouncedRound'; | ||
|
||
@Component({ | ||
selector: 'ui-scroll', | ||
changeDetection: ChangeDetectionStrategy.OnPush, | ||
templateUrl: './ui-scroll.component.html', | ||
styleUrls: ['./ui-scroll.component.css'] | ||
}) | ||
|
||
export class UiScrollComponent implements OnInit { | ||
export class UiScrollComponent implements OnInit, OnDestroy { | ||
|
||
@Input() datasource; | ||
@ContentChild(TemplateRef) templateVariable: TemplateRef<any>; | ||
|
||
onScrollListener: Function; | ||
|
||
constructor(private elementRef: ElementRef, private renderer: Renderer) { | ||
constructor(private changeDetector: ChangeDetectorRef, private elementRef: ElementRef, private renderer: Renderer2) { | ||
} | ||
|
||
ngOnInit() { | ||
Elements.initialize(this.elementRef); | ||
Data.initialize(this); | ||
this.onScrollListener = this.renderer.listen(Elements.viewport, 'scroll', (event) => { | ||
const direction = Direction.byScrollTop(); | ||
Process.fetch.run(direction); | ||
}); | ||
Process.fetch.run(Direction.bottom); | ||
Process.fetch.run(Direction.top); | ||
Workflow.initialize(this); | ||
this.onScrollListener = this.renderer.listen(Elements.viewport, 'scroll', (event) => | ||
debouncedRound(() => Workflow.run(event), 25) | ||
); | ||
Workflow.run(Direction.bottom); | ||
Workflow.run(Direction.top); | ||
} | ||
|
||
ngOnDestroy() { | ||
this.onScrollListener(); | ||
} | ||
|
||
} |
Oops, something went wrong.