Checking the value of an exposed state in plugin builder

To any plugin builders out there- Does anyone know how to check the value of an exposed state?

In a plugin I’m building, first I’m setting a couple of states by doing

instance.publishState();

Then I’m triggering an event by doing

instance.triggerEvent();

When the event is triggered, in the Bubble workflow I’m modifying a Thing using the values set in the exposed states. However, I’m seeing an issue where if the event is triggered too rapidly, sometimes Things’ values will be modified to null. I think what’s happening is the event is triggered before the state has been properly set. How can I check that publishState has successfully completed? Any ideas would be much appreciated!

I’m new to JS and to Bubble plugins but in a little plugin that I’m building, I encountered a similar problem. In my case, the problem was that a property I needed in order to set my exposed state was not yet set/read. So instance.publishState(); would always return null until I forced an update. I resolved it by testing for null in the property before setting the state.

I know this is not exactly what you’re facing but maybe it sparks something.

Yeah, that was what I thought was going on, but I added a check for null and print the value I’m publishing to the console before triggering the event and the console value is correct and it still happens, so I’m reasonably sure the issue is happening because there’s no delay between publish state and trigger event. I guess I could just add an interval between the two but I’d much rather know for sure that the publish state has been successful.
Thanks for the help anyway!

1 Like

Please report back if you find a solution or even a workaround as I have now hit this problem again myself and this time, like you, testing for null doesn’t help.

I’ve read (I think from @mishav) that triggering an event might help but the concept of events escapes me and my plugin doesn’t need an event that the user can use in the editor.

Maybe when publishing a value, Bubble sets it to null briefly, and the previous event code is reading it at this time?

Can you explain more of what type of value, and how fast the event is being triggered? I’ve done tests with number values and several thousand events per second and I haven’t seen this issue, but then I haven’t looked for the issue!

@louisadekoya can you explain more of what your situation is?

Thanks @mishav. I’m not certain that my issue is the same as @dambusmedia and I don’t want to hijack his post if it isn’t. Later on today I’ll outline my issue in a separate post and link to it here is that’s okay.

Hi @mishav

I’m setting a date value and a string (to a thing’s unique value), and tbh I’m not certain it’s related to the speed of triggering the event, I’ve seen it happen when I’ve just triggered it once. It seemed to occur randomly so I noticed it more when I just spammed the trigger button.

Initially I was doing a search in the workflow editor for things with the unique value I’d set, once the event was triggered, but now I’ve refactored the plugin code so that instead I’m setting a custom state straight to the Thing object, and I haven’t seen the issue happen since, so fingers crossed it was that that was causing it!