Add cross-env and ListenerRSSInfo is an interface

This commit is contained in:
Amaury
2021-02-14 17:07:23 +01:00
parent 43e93671dd
commit f8c9eb7d35
5 changed files with 134 additions and 163 deletions

View File

@ -1,44 +1,6 @@
export class ListenerRSSInfos {
_name: string = ""; // name of the listener
_address: string = ""; // feed's address
_timeloop: number | undefined = 5 * 60; // update time RSS feed
_customfields: [string, string | [string, string]][] | undefined = undefined; // rss fields custom
constructor(
name: string,
address: string,
timeloop?: number,
customfields?: [string, string | [string, string]][]
) {
if (name !== undefined && address !== undefined) {
this._name = name;
this._address = address;
this._timeloop = timeloop;
this._customfields = customfields;
} else throw new Error("Bad constructor's args");
}
set timeloop(value) {
this._timeloop = value;
}
set customfields(value) {
this._customfields = value;
}
get name() {
return this._name;
}
get address() {
return this._address;
}
get timeloop() {
return this._timeloop;
}
get customfields() {
return this._customfields;
}
export interface ListenerRSSInfos {
name: string; // name of the listener
address: string; // feed's address
timeloop?: number; // update time RSS feed
customfields?: [string, string | [string, string]][]; // rss fields custom
}

View File

@ -7,25 +7,14 @@ export class ListenerRss {
name: string = "";
address: string = "";
timeloop: number = DEFAULT_TIMELOOP; // time in seconds
customfields: [string, string | [string, string]][] | undefined = undefined;
customfields?: [string, string | [string, string]][];
// private fields
parser: Parser | undefined = undefined;
loopRunning: boolean = false;
constructor(
name: string | ListenerInfo,
address?: string,
timeloop?: number,
customfields?: [string, string | [string, string]][]
) {
if (name instanceof ListenerInfo) {
// constructor with 1 arg
this.setData(name);
} else if (address !== undefined) {
// construct with between 2 and 4 args
this.setData(new ListenerInfo(name, address, timeloop, customfields));
} else throw new Error("the constructor must have args");
constructor(config: ListenerInfo) {
this.setData(config);
this.setParser();
}
@ -46,12 +35,12 @@ export class ListenerRss {
setData(infos: ListenerInfo) {
// Set data
this.name = infos._name;
this.address = infos._address;
this.name = infos.name;
this.address = infos.address;
this.timeloop =
infos._timeloop === undefined ? DEFAULT_TIMELOOP : infos._timeloop;
infos.timeloop === undefined ? DEFAULT_TIMELOOP : infos.timeloop;
this.customfields =
infos._customfields === undefined ? undefined : infos._customfields;
infos.customfields === undefined ? undefined : infos.customfields;
}
fetchRSS(): any {