I have been working with reactJS for a few weeks but I stay relatively new to React and Flyd. As a matter of fact, I tried to combine a flyd stream like this :

    const informations$ = flyd.combine(Test.fun2, [lang$, args$])

where lang$ and args$ are two other streams

into Test file, I have this :

class TestClass {
  private fun1() {
    console.log("fun1")
  }
  private fun2(lang$, brand$, state$) {
    console.log("fun2")
    this.fun1()
  }
}

export const Test = new TestClass()

And this doesn't work. My console only shows "fun2", while "fun1" is never printed. It seems that this.fun1 is undefined.

However, I could make it work with the following :

class TestClass {
  private fun1() {
    console.log("fun1")
  }
  private fun2() {
    console.log("fun2")
    this.fun1()
  }
  public fetchData = (lang$, brand$, state$) => {
    this.fun2(lang$, brand$, state$)
  }
}

export const Test = new TestClass()

It seems that the arrow function allowed me to keep the context as the class. As I am new to javascript, I don't understand why this (the context) isn't inside the scope TestClass when called through flyd

(however, when called without flyd, it works fine both way)

Could someone give me some insight on how flyd and javascript context work for this to happen ?

Many thanks.

0 Answers