I am prototyping a project that requires a unique id for each functions. here is an example.
function Example(name, uuid) {
...
}
function start() {
Example("Jeeva", 1)
if (...) {
Example("Peter", 2)
}
Example("June", 3)
}
As you can see the start function may called multiple times. but I want the id to be same. the id doesn't have to be a number it could be anything but has to unique to that function call.
I tried to store the ids in a list outside the start function and adding the id on first call and shifting them on other calls. But the issues is inside the if statement the function might not be executed. so after the first call if the condition changes then Example function will be called and shifting the id will return fails.
Can anyone point me in the right direction or is it impossible in this case?
Edit
OK, let me tell you why do I want this functionality. Simply put I am trying jetpack compose. If you don't know how jetpack compose works. It's a declarative UI framework. It updates (recompose) it's UI on state changes.
I am not doing this project for production, just to learn (out of curiosity).
here is an example that I am testing right now.
import { Compose } from "../src/core/Compose"
import { Text } from "../src/composable/Text"
const App = scope => {
let text = scope.stateOf("hello", 1)
Text({
text: text.value
}, scope, 1)
if (text.value === "hello, world") {
Text({ text: "Hi" }, scope, 2)
}
if (text.value == "hello") {
setTimeout(() => text.value = "hello, world" , 2000)
}
}
new Compose("#app").mount(App)
As you can see I am passing unique numbers at the end of each composables and state. this allows me to find them on recomposition.