replace some type specification from any to more accurate
This commit is contained in:
		@@ -24,8 +24,9 @@ export class ListenerRss {
 | 
			
		||||
      this.customfields !== undefined
 | 
			
		||||
        ? {
 | 
			
		||||
            customFields: {
 | 
			
		||||
              feed: [],
 | 
			
		||||
              item: Object.entries(this.customfields).map(([, value]) => {
 | 
			
		||||
                return Array.isArray(value[1]) ? value[1][0] : value[1];
 | 
			
		||||
                return Array.isArray(value) ? value[0] : value;
 | 
			
		||||
              }),
 | 
			
		||||
            },
 | 
			
		||||
          }
 | 
			
		||||
@@ -42,7 +43,7 @@ export class ListenerRss {
 | 
			
		||||
    this.customfields = infos.customfields;
 | 
			
		||||
  }
 | 
			
		||||
 | 
			
		||||
  fetchRSS(): any {
 | 
			
		||||
  fetchRSS(): Promise<any> {
 | 
			
		||||
    // TODO Pas Bien
 | 
			
		||||
    if (this.parser !== undefined && this.address !== undefined) {
 | 
			
		||||
      return this.parser.parseURL(this.address).catch((err) => {
 | 
			
		||||
@@ -55,23 +56,25 @@ export class ListenerRss {
 | 
			
		||||
   * @brief call the callback function each looptime
 | 
			
		||||
   * @param callback function who's going to be called with the latest get
 | 
			
		||||
   */
 | 
			
		||||
  start(callback: any) {
 | 
			
		||||
    // TODO any = Pas bien !!
 | 
			
		||||
    /**
 | 
			
		||||
     * Un des soucis qu'on a c'est sur le typage de l'objet de retour. le problème étant que la nature de l'obj de
 | 
			
		||||
     * retour ne peut pas etre connue puisque il depend des custom fields qui sont definit par l'utilisateur. L'idée
 | 
			
		||||
     * pourrait etre de creer une classe generique (cf le type CustomFields du ficher index.d.ts du package rss-parser).
 | 
			
		||||
     * Après quelques recherches ca doit etre la manière ""correct"" de faire. Entre autre avec l'utilisation des mots
 | 
			
		||||
     * clés keyof U ou encore Array<keyof U>. Je vais continuer a gratter dans cette direction perso.
 | 
			
		||||
     */
 | 
			
		||||
  start(
 | 
			
		||||
    callback: (
 | 
			
		||||
      obj: { [key: string]: any } | undefined,
 | 
			
		||||
      err: Error | undefined
 | 
			
		||||
    ) => void
 | 
			
		||||
  ) {
 | 
			
		||||
    this.loopRunning = true;
 | 
			
		||||
 | 
			
		||||
    (async () => {
 | 
			
		||||
      while (this.loopRunning) {
 | 
			
		||||
        this.fetchRSS().then((obj: any, err: any) => callback(obj, err)); // TODO Erreur a la compile
 | 
			
		||||
        await new Promise((res) => setTimeout(res, 2000));
 | 
			
		||||
      }
 | 
			
		||||
    })();
 | 
			
		||||
    const fun = () => {
 | 
			
		||||
      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();
 | 
			
		||||
  }
 | 
			
		||||
 | 
			
		||||
  /**
 | 
			
		||||
 
 | 
			
		||||
		Reference in New Issue
	
	Block a user