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

Reorganize package #2

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

Reorganize package #2

wants to merge 7 commits into from

Conversation

philippjfr
Copy link

@philippjfr philippjfr commented Jan 24, 2022

Still haven't gotten this fully working unfortunately but I'm still working on it. Some notes on why this wasn't really working at all before now:

  • Bokeh relies on bokeh.ext.json to be present both for the build step and inside the Python package to detect whether a particular Python package bundles an extension
  • __implementation__ is for packages that are compiled on the fly, for bundled extension we just need to make sure that the Bokeh model references the correct __module__.
  • register_models should be given the Model not the View

So to avoid duplicating the bokeh.ext.json and fiddling with paths too much I've moved the idom-bokeh-extension into the Python package for now. It may be possible to keep them separate but I've never tried and currently I expect this to be somewhat brittle.

Unfortunately there are still some issues:

  • react.js references process.env.NODE_ENV in a bunch of places, I'm guessing the bundler should somehow optimize this away (or something) but bokeh's custom bundler does not appear to do so.
  • If I manually define process.env.NODE_ENV I still get the following error: Uncaught TypeError: Cannot redefine property: JsonPatchError

Closes: #1

@philippjfr
Copy link
Author

Resolved the process.env.NODE_ENV issue now with the rollup config I found in some of your code. Unfortunately I still see Uncaught TypeError: Cannot redefine property: JsonPatchError.

@philippjfr
Copy link
Author

If I comment out these lines in the generated JS it does work:

    __esExport("JsonPatchError", helpers_mjs_1.PatchError);
    __esExport("deepClone", helpers_mjs_1._deepClone);
    __esExport("escapePathComponent", helpers_mjs_1.escapePathComponent);
    __esExport("unescapePathComponent", helpers_mjs_1.unescapePathComponent);
    

And there's probably some way to disable those exports. At that point we can finally render the output but run into serialization issues when we trigger events:

Uncaught Error: [object DOMRect] is not serializable

@philippjfr
Copy link
Author

Okay, worked around the __esExport issue now, this now renders:

import idom
import idom_bokeh
import panel as pn

from idom_bokeh.panel import IDOM

pn.extension()

@idom.component
def ClickCount():
    count, set_count = idom.hooks.use_state(0)

    return idom.html.button(
        {"onClick": lambda event: set_count(count + 1)},
        [f"Click count: {count}"],
    )

IDOM(ClickCount, width=300)

Will tackle the serialization issues tomorrow some time.

@philippjfr
Copy link
Author

Had to do some patching of the events since the serializer didn't like serializing the boundingClientRect.

@philippjfr philippjfr changed the title WIP: Reorganize package Reorganize package Jan 24, 2022
@philippjfr
Copy link
Author

@rmorshea This is working for me now.

@rmorshea
Copy link
Member

Will review this tonight. Thanks for looking into it so quickly!

src/idom_bokeh/src/index.ts Outdated Show resolved Hide resolved
src/idom_bokeh/src/index.ts Outdated Show resolved Hide resolved
Comment on lines 22 to 27
if (e.target?.boundingClientRect != null) {
e.target.boundingClientRect = {...e.target.boundingClientRect}
}
if (e.currenttarget?.boundingClientRect != null) {
e.target.boundingClientRect = {...e.currentTarget.boundingClientRect}
}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you explain a bit of the issue here? I haven't encountered this when serializing with JSON.stringify. Does this need a fix in IDOM core's event-to-object implementation? It should be simple enough to use a spread operator here.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think Bokeh just doesn't serialize custom objects so the spread operator to turn it into a regular object is indeed all that's needed.

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.

Pre-built Extension Not Working
2 participants