replace some type specification from any to more accurate and adding more comments
This commit is contained in:
parent
960d754604
commit
7d404c3ea9
|
@ -13,11 +13,18 @@ export class ListenerRss {
|
|||
parser: Parser | undefined = undefined;
|
||||
loopRunning: boolean = false;
|
||||
|
||||
/**
|
||||
* @brief constructor
|
||||
* @param config ListenerRSSInfos interface who's contain the ListenerInfos
|
||||
*/
|
||||
constructor(config: ListenerInfo) {
|
||||
this.setData(config);
|
||||
this.setParser();
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Private function. Is useed to initilize the parser object with the customfields var
|
||||
*/
|
||||
setParser() {
|
||||
// set parser
|
||||
this.parser = new Parser(
|
||||
|
@ -34,6 +41,10 @@ export class ListenerRss {
|
|||
); // if customfield is set -> let's set the parser with, else let the option empty
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Private function. Initialized the listener with an ListenerRSSInfos interface
|
||||
* @param infos ListenerRSSInfos interface who's contain the ListenerInfos
|
||||
*/
|
||||
setData(infos: ListenerInfo) {
|
||||
// Set data
|
||||
this.name = infos.name;
|
||||
|
@ -43,8 +54,11 @@ export class ListenerRss {
|
|||
this.customfields = infos.customfields;
|
||||
}
|
||||
|
||||
fetchRSS(): Promise<any> {
|
||||
// TODO Pas Bien
|
||||
/**
|
||||
* @brief use the parseURL function from rss-parser with the objects datas
|
||||
* @return return a promise with the received data
|
||||
*/
|
||||
fetchRSS(): Promise<Parser.Output<any>> {
|
||||
if (this.parser !== undefined && this.address !== undefined) {
|
||||
return this.parser.parseURL(this.address).catch((err) => {
|
||||
throw new Error("bad address or no access : " + err);
|
||||
|
@ -61,26 +75,27 @@ export class ListenerRss {
|
|||
obj: { [key: string]: any } | undefined,
|
||||
err: Error | undefined
|
||||
) => void
|
||||
) {
|
||||
): void {
|
||||
this.loopRunning = true;
|
||||
|
||||
const fun = () => {
|
||||
const fun: () => void = () => {
|
||||
this.fetchRSS()
|
||||
.then((obj: { [key: string]: any }) => callback(obj, undefined))
|
||||
.catch((err) => callback(undefined, err));
|
||||
};
|
||||
let fun_loop = () => {
|
||||
fun();
|
||||
console.log("while");
|
||||
if (this.loopRunning) setTimeout(fun_loop, this.timeloop * 1000);
|
||||
};
|
||||
fun_loop();
|
||||
|
||||
(async () => {
|
||||
while (this.loopRunning) {
|
||||
await fun();
|
||||
await new Promise((res) => setTimeout(res, this.timeloop * 1000));
|
||||
}
|
||||
})();
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief stop the async function
|
||||
*/
|
||||
stop() {
|
||||
stop(): void {
|
||||
this.loopRunning = false;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -34,8 +34,9 @@ describe("test class RSS: jsonfile", function () {
|
|||
let stubListener: sinon.StubbedInstance<Listeners>;
|
||||
let stubParser: sinon.StubbedInstance<Parser>;
|
||||
|
||||
const mockedRSSOutput: any = {
|
||||
// TODO any = pas bien
|
||||
const mockedRSSOutput: Parser.Output<{
|
||||
"media:group": { [key: string]: string | [any] };
|
||||
}> = {
|
||||
items: [
|
||||
{
|
||||
title: "my title 00",
|
||||
|
@ -96,7 +97,7 @@ describe("test class RSS: jsonfile", function () {
|
|||
}
|
||||
});
|
||||
stubListener.setParser();
|
||||
stubListener.fetchRSS.resolves(stubParser.parseURL(stubListener.address));
|
||||
stubListener.fetchRSS.returns(stubParser.parseURL(stubListener.address));
|
||||
} else throw new Error("myListener need to be initiliaze before the stub");
|
||||
};
|
||||
|
||||
|
|
Loading…
Reference in New Issue
Block a user