Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Treehouse does JSON decoding on the main thread #2145

Open
1 of 2 tasks
swankjesse opened this issue Jun 26, 2024 · 4 comments
Open
1 of 2 tasks

Treehouse does JSON decoding on the main thread #2145

swankjesse opened this issue Jun 26, 2024 · 4 comments

Comments

@swankjesse
Copy link
Collaborator

swankjesse commented Jun 26, 2024

Host side bindings look like this:

  override fun apply(change: PropertyChange, eventSink: EventSink) {
    val widget = _widget ?: error("detached")
    when (change.tag.value) {
      1 -> widget.avatars(json.decodeFromJsonElement(serializer_0, change.value))
      4 -> widget.size(json.decodeFromJsonElement(serializer_1, change.value))
      2 -> widget.badge(json.decodeFromJsonElement(serializer_2, change.value))
      3 -> {
        val onClick: (() -> Unit)? = if (change.value.jsonPrimitive.boolean) {
          OnClick(json, change.id, eventSink)::invoke
        } else {
          null
        }
        widget.onClick(onClick)
      }
      5 -> widget.isMerchant(json.decodeFromJsonElement(serializer_3, change.value))
      else -> mismatchHandler.onUnknownProperty(WidgetTag(15), change.tag)
    }
  }

We should decode the change.value of the PropertyChange from JSON to a host-side model on the Zipline thread instead.


@JakeWharton
Copy link
Collaborator

How do you put something on the zipline thread?

We can trivially expose the list of property IDs like we do children IDs, and then offer a function to look up the KSerializer for a given property ID. We can look up the protocol node given the widget ID, but to get Zipline to use that before dispatch to the UI thread we need injection into the KSerializer for Change.

@JakeWharton
Copy link
Collaborator

Oh I'm dumb. Treehouse is what moves to the UI thread. Okay this should be doable.

@JakeWharton JakeWharton changed the title Protocol does JSON decoding on the main thread Treehouse does JSON decoding on the main thread Jul 31, 2024
@JakeWharton
Copy link
Collaborator

Need to wait a week or two for the guest-side changes to roll out internally before we can land this.

@JakeWharton
Copy link
Collaborator

This is unblocked!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants