Right now, if the original implementation has a function A, which calls another function B, and then if the user overrides function B and then if A is called, it does not call user's B, but instead calls the original B.
This would break logic in many cases. At the moment, this affects the JS SDKs and the golang SDK.
The trick here is to not use arrow functions for any of the functions in the recipe / api interface implementaiton. This allows the this variable to point to functions in the new object returned by the user solving this problem.
Then when the user calls the original function, they must bind it to this object as shown below.
Small example:
class Aa {
m: string = "m"
someFunc = function () {
console.log("original someFunc", this.m)
this.someOtherFunc()
}
someOtherFunc = function () {
console.log("original someOtherFunc")
}
}
let oI = new Aa();
let a = {
...oI,
someFunc: function () {
oI.someFunc.bind(this)();
},
someOtherFunc: function () {
console.log("overrided a someOtherFunc")
}
}
let b = {
...a,
someFunc: function () {
a.someFunc.bind(this)();
},
someOtherFunc: function () {
console.log("overrided b someOtherFunc")
}
}
b.someFunc();
Golang fix:
The trick here is to make all the recipe / api interface functions pointers to functions, and then get the user to change the pointer value when overriding it like so:
Now if a user creates an instance of Recipe2, and then overrides someFunc3 to do what they like (and semantically someFunc3 is similar to someFunc2), calling recipe2.someFunc() will not have the same expected behaviour.
Right now, if the original implementation has a function
A
, which calls another functionB
, and then if the user overrides functionB
and then ifA
is called, it does not call user'sB
, but instead calls the originalB
.This would break logic in many cases. At the moment, this affects the JS SDKs and the golang SDK.
JS fix (node, auth-react, website, react-native SDKs):
The trick here is to not use arrow functions for any of the functions in the recipe / api interface implementaiton. This allows the
this
variable to point to functions in the new object returned by the user solving this problem.Then when the user calls the original function, they must bind it to
this
object as shown below.Small example:
Golang fix:
The trick here is to make all the recipe / api interface functions pointers to functions, and then get the user to change the pointer value when overriding it like so:
SignUp
is a pointer to the actual sign up function, andSignIn
is a pointer to the actual sign in function.TODO:
get
functionAnother important issue:
Here is the situation:
Now if a user creates an instance of
Recipe2
, and then overridessomeFunc3
to do what they like (and semantically someFunc3 is similar to someFunc2), calling recipe2.someFunc() will not have the same expected behaviour.