This file contains hidden or 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
fs.readdir(source, function (err, files) { | |
if (err) { | |
console.log('Error finding files: ' + err) | |
} else { | |
files.forEach(function (filename, fileIndex) { | |
console.log(filename) | |
gm(source + filename).size(function (err, values) { | |
if (err) { | |
console.log('Error identifying file size: ' + err) | |
} else { |
This file contains hidden or 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
export class GamesComponent implements OnDestroy { | |
private _gamesSubscription:Subscription; | |
constructor(private _gamesService:GamesService){ | |
/** | |
* If we had already emitted values down this observable we would immediately receive them here, without re-requesting them. | |
* We would be able to quickly populate the component and if need re-request the data from within the ngOnInit lifecycle hook. | |
*/ | |
this._gamesSubscription = this._gamesService.gamesChanged$.subscribe((games) => { |
This file contains hidden or 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
@Injectable() | |
export class GamesService { | |
/** Internal model state */ | |
private games:Object[]; | |
/** Private Subject **/ | |
private _gamesSource:Subject<Object[]> = new Subject<Object[]>(); | |
/** Public Observer **/ |
This file contains hidden or 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
<div class="media-body"> | |
<p>{{ competition?.description }}</p> | |
<p>{{ competition?.user?.name }}</p> | |
<p>{{ competition?.game?.title?.shortName }}</p> | |
</div> |
This file contains hidden or 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 is a special hook because it is called before your component is instantiated. | |
* Its parameters are (next, previous) which are the components you're routing to and the component | |
* you've come from (or null if you have no history) respectively. | |
*/ | |
@CanActivate((next, prev) => { | |
// No simple way to load data, how to easily inject services or how to provide the result to componenet once loaded. | |
// Work arounds can be found but are not ideal IMHO. | |
return true; | |
}) |
This file contains hidden or 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
export class DashboardComponent implements OnActivate { | |
routerOnActivate(nextInstruction:ComponentInstruction, prevInstruction:ComponentInstruction):any|Promise<any> { | |
// Load some data ... | |
} | |
} |
This file contains hidden or 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
export class DashboardComponent implements OnInit { | |
ngOnInit():any { | |
// Load some data ... | |
} | |
} |
This file contains hidden or 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
// Include the full set of RxJs features | |
import "rxjs/Rx"; | |
// Add individual imports per function which is required | |
import 'rxjs/add/operator/share'; | |
import 'rxjs/add/operator/map'; | |
import 'rxjs/operator/delay'; | |
import 'rxjs/operator/mergeMap'; | |
import 'rxjs/operator/switchMap'; |
This file contains hidden or 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
export class AdminDashboardComponent implements OnDestroy { | |
/** Public data */ | |
competitions:Competition[]; | |
/** Subscriber */ | |
private _competitionsSubscription:Subscription; | |
constructor(private _competitionsService:CompetitionsService) { | |
// Subscribe an changes which may happen |
This file contains hidden or 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
export class CompetitionsService { | |
// Create a Subect to observe | |
private _competitionsSource:Subject<Competition[]> = new Subject<Competition[]>(); | |
// Publicly expose the Observable - called share() to allow multiple observers | |
competitionsChanged$:Observable<Competition[]> = this._competitionsSource.asObservable().share(); | |
constructor(private _http:Http) { | |
_http.get('http://localhost:8080/competitions') |