This applies Array.filter to create a new array with only the defined items in orderedData.
Because orderedData has objects or undefined as items, if it is an object the value !!item will be true and if it is undefined it will be false.
Javascript objects when used in boolean contexts are seen as true, but when a context needs a real boolean object, you can just use !! before it (negation of negation) resulting in the original value as a real boolean, otherwise you could receive typescript errors about incorrect type (if you used filter(item => item) it would work in javascript, but in typescript it would be a type error).
Update
Now that I tried, filter(item => item) seems to work too (I don’t know if the problem happened only in previous versions of typescript, or if I was just mistaken).
Update 2
It seems it was an error in older versions, but not now:
What I think I would do in this situation is to move all the scheduling logic into the provider. I always try to design providers so that they give pages exactly what they want, instead of making the pages cobble stuff together from pieces exposed by the provider. With that viewpoint in mind, I’m thinking something like this: (untested and needs better error handling, though)
interface Payload {
// idk what goes in here
}
interface DayRecord {
when: Date;
displayWhen: string;
payload: Payload;
}
declare function require(mn: string): any;
let format = require('date-fns/format');
let addDays = require('date-fns/addDays');
export class Provider {
getDay(day: Date): Observable<DayRecord> {
return this.getSpecificAPOD(day).pipe(
map((apod) => {
return {
when: day,
displayWhen: format(day, "YYYY-MM-DD"),
payload: apod,
};
}));
}
getDays(starting: Date, ndays: number): Observable<DayRecord[]> {
return forkJoin(range(0, ndays).pipe(
mergeMap((doff) => this.getDay(addDays(starting, doff)))));
}
}
Muito obrigado @joshmorony.
Me ajudou horas de pesquisa.
Vc tem feito um ótimo trabalho na internet para divulgar o desenvolvimento em IONIC.
Sempre vejo ótimos artigos seus.