Properties.bubble.auto_binding() safe to use?

I just saw this function on the Rich Text Editor from Bubble, but I don’t see that in the list of stuff in the plugin editor.

So everyone has to build little hacks to get around the loading. Is this a good hack (source: Rich Text plugin)?

 // shorthand for d container
  const d = instance.data

  if (!d.has_been_reconciled){
    // The instance hasn't been reconciled yet, and we risk losing what was updated, so we refill the data.
    // Why we do this? Because the instance can update again before it is reconciled, and in that case updated_props is empty
    // since the properties were copied at the previous update run. But the editor wasn't ready to be displayed then, so the next time update runs,
    // we lose all the information about what had been updated.
    for (const key in properties) {
      if (key === 'bubble') continue
      d.updated_props[key] = properties[key]
      d.last_update_props[key] = properties[key]
    }

    for (const key in properties.bubble) {
      const property = properties.bubble[key]()
      d.last_update_bubble_props[key] = property
      d.updated_bubble_props[key] = property
    }
  }

  // Get rid of a lot of odd issues with extra updates running by returning on identical updates
  if (
    Object.keys(d.updated_props).length === 0 &&
    Object.keys(d.updated_bubble_props).length === 0
  ) return

@rico.trevisan You will need to enable autobinding in your plugin element:

Then it will show up:

But even when you do, that function is not listed properties.bubble.auto_binding(), correct? Wait, does it show up with autocomplete?

Mm I have never used (or seen) properties.bubble.auto_binding() but it will for sure be nice to have. Did you find out if it autocompletes?

1 Like

I just tried and there is properties.bubble.auto_binding. It looks like a function returning true if autobinding is enabled.
Of course because it’s not in the official docs it’s probably not safe to use (bubble can legitimately decide to remove it at any time)

1 Like

No, I found it in the code of the Rich Text Plugin by Bubble. (see image on first post).


I hear my inner-@keith gesturing snarky obscenities and pointing at the color variables thread. “Not even the ‘safe’ stuff is safe to use.” :sweat_smile:


Since I’ve got 2 experts here, let me ask you a question: how do you handle the saving of an output? @Thimo , I’ve been studying your Rich Text Editor (ModernJS) plugin’s code, but I haven’t been able to test it. What would happen if I have a page with:

  • your rich text editor which gets its initial content from the parent group
  • a dropdown that allows me to change the data of that parent group
  • a workflow that fires when the editor’s content has changed
    • that then makes a change to the parent’s group thing and saves the output to it.

My plugin gets all loopy. It will allow me to type, but if I hit space it resets the content, and a bunch of other unreliable stuff.

Diving into Thimo’s code, I’m wondering if this is your work-around to avoid that. But I need a couple of days of reading and re-reading this to completely grok it (my fault, not yours. I’m slow.)

    if (instance.data.initial_data != properties.initial_data && instance.data.initial_data !== null && properties.initial_data !== null && instance.data.editor.blocks !== undefined) {

        var blockCount = JSON.parse(properties.initial_data).blocks.length

        instance.publishState('total_block_count', blockCount);

        if (properties.initial_data !== null && blockCount > 0) {

            instance.publishState('saved_data',properties.initial_data)
            instance.data.editor.blocks.render(JSON.parse(properties.initial_data))
            instance.publishState('saved_data_html', instance.data.edjsParser.parse(JSON.parse(properties.initial_data)).join(' '));

            setTimeout(() => {
                instance.publishState('saved_data',properties.initial_data)
            }, 100)
        }
    }
    
    instance.data.initial_data = properties.initial_data
1 Like

Autobinding in element plugins is a real thing. As @Thimo points put you just have to enable it and then you have access to the publish function (which is a method on instance, instance.publishAutobinding(value). The bound value is passed to update as properties.autobinding. (These names may have changed since it was originally implemented, but the autobinding-related stuff shows up in “docs” when enabled.)

Original announcement here:

1 Like

Do you sometimes feel like @keith is the devil on your shoulder, willing you to reply harshly to less than intelligent questions?

Then I think @mikeloc is on the other shoulder lol.

3 Likes

All things must be kept in balance, @troy.roberge!

@rico.trevisan - in more direct answer to the question you posed, it does seem that properties.bubble.auto_binding() returns true if autobinding is enabled for the element and false if autobinding has not been selected by the user. I’d say it’s safe to use even though they forgot to document that.

2 Likes

Thanks Keith!

Are you referring to my question?

The clarity of my writing leaves much to be desired; it is as clear as muddy water. However I’m hoping it was clear that I was not asking about the auto-binding feature, but about that specific undocumented function call.

Ha @rico.trevisan, I’m sure @troy.roberge wasn’t criticizing your question. He was making a funny about my tendency to snark vs @mikeloc’s saint-like patience. :wink:

3 Likes

No, sorry. I was taking onto your channelling of @keith to poke fun at him. Nothing more :slight_smile:

1 Like

I guess this is not safe anymore…

1 Like

Actually, my plugin had autobinding suddenly turned off. I wonder if it’s because I am using Bask…

3 Likes