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

feat(anywidget): Reduce Backbone dependency, implement minimal JS runtime over comm #479

Draft
wants to merge 7 commits into
base: main
Choose a base branch
from

Conversation

manzt
Copy link
Owner

@manzt manzt commented Mar 18, 2024

This is an experiment to further reduce anywidget's dependency on @jupyter-widgets/base (and thus Backbone). The idea is that by managing the comm ourselves, we can more readily implement adapters for other popular frontend frameworks without the overhead/dependency of another framework. Additionally, this would allow us to configure things like serializers custom serializers.

However, it's increasingly clear just how coupled classic Backbone-based widgets are with the rest of the Jupyter ecosystem. This PR is kind of massive, so I'm not sure how viable it is. There are many rough edges with trying to understand the boundaries between widget manager and DOMWidgetView/DOMWidgetModel, and expected APIs.

So far my approach has been manually looking at the ipywidgets source code and only exposing public APIs on the Model and View that are used by the WidgetManager. We will only go forward with this PR if we are able to faithfully implement anywidget's current API.

My hope is that we can have different, "mode"s for anywidgets, one of which could be more low-level and for front-end framework authors. For example, the existing Backbone widgets could be implemented with this like:

export default {
  mode: "comm",
  comm_open({ comm, attributes }) {
    let model = new Backbone.Model({ attributes });
    comm.on_msg((msg) => /* update model */);
    comm.on_close(() => /* destroy model */);
    model.save_changes = () => {
      comm.send({ content: { method: "update", /* ... */ });
    }
    return model;
  },
  initialize({ model }) {
  
  },
  render({ model, el }) {

  }
}

Copy link

changeset-bot bot commented Mar 18, 2024

⚠️ No Changeset found

Latest commit: 157b09e

Merging this PR will not cause a version bump for any packages. If these changes should not result in a new version, you're good to go. If these changes should result in a version bump, you need to add a changeset.

This PR includes no changesets

When changesets are added to this PR, you'll see the packages that this PR includes changesets for and the associated semver types

Click here to learn what changesets are, and how to add one.

Click here if you're a maintainer who wants to add a changeset to this PR

@manzt manzt changed the title [wip] feat: Reduce Backbone dependency, implement minimal JS runtime over comm [wip] feat(anywidget): Reduce Backbone dependency, implement minimal JS runtime over comm Mar 18, 2024
@manzt manzt marked this pull request as draft March 18, 2024 00:31
@manzt manzt changed the title [wip] feat(anywidget): Reduce Backbone dependency, implement minimal JS runtime over comm feat(anywidget): Reduce Backbone dependency, implement minimal JS runtime over comm Mar 18, 2024
@manzt manzt force-pushed the main branch 2 times, most recently from b8bf0af to 263e583 Compare March 23, 2024 14:57
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant