ELI5: What are states initialization and circular dependencies?

It’s probably easier to explain how to generate a circular dependency error:

  • create a plugin element with a filed of type text, let’s call it “textinput”
  • add a state of type text, let’s call it “textoutput”
  • let’s initialize “textoutput”
    image
  • now in the app editor let’s assign a value to “textinput” that reference the element state
    image
  • go to preview and watch your error :slight_smile:

It looks complicated but it’s the equivalent of this javascript code
image
it’s just made in 2 steps between the plugin code and the editor

You are literally telling bubble to inizialite the state “textoutput” with the value of the state “textoutput”.

A solution is to initialize the state in the initialize function where you don’t have the properties and you can only initialize the state to a static value. Then publish the state value in the update function.
image
image

I hope it’s more clear now

Cheers

Mariano

3 Likes