Skip to content

Expanded JavascriptBindings options #367

Open
@andrewleech

Description

@andrewleech

The current scheme for binding python objects into the javascript namespace is limited to individual functions, properties and functions on an object.
These can only be bound to a name directly on the javascript window object.

Unfortunately this limits the complexity of javascript api's that can the implemented in python.

To allow more complex functionality some work is in progress to expand the options available, specifically to allow application level implementation of the html notifications api: https://developer.mozilla.org/en/docs/Web/API/notification

The current wip implementation can be found on my fork at: https://github.com/andrewleech/cefpython/tree/bindings_features

One feature is to allow bound objects to be callable. I do this by detecting the call function on the python object and creating a function as the top level object rather than a basic object. The other python methods are attached to that then.

To allow more complex structures of bound functions & properties I added the ability to bind python functions/properties/objects to existing objects on window by recognizing and parsing "." in the binding name.
This works fairly well however due to order in which the binding occurs (functions, then props, then objects) this limits the complexity of the object that can be built up.

I then decided it would all be much cleaner if all the properties of the python module could be bound instead of having to bind them all one-by-one trying to build up the correct object in js.
I understand the reason you decided not to do this due to potential confusion from the python / js properties not being synced so my implementation requires an option to be passed to enable all properties to be bound.
This way the user will have presumably seen to docs on how to use this option and understand that the properties are bound by copy and will not be synced. It's not perfect but does allow for functionality the current implementation does not.

TODO:

  • Clean up detection/describing functions to be bound on objects, the current method is a bit of a hack
  • Related to above, frameId issues during binding need to be examined and resolved.
  • Update documentation / examples
  • Clean up code formatting

For further discussions see: https://groups.google.com/forum/?utm_medium=email&utm_source=footer#!topic/cefpython/HVUePvzRXbc

Metadata

Metadata

Assignees

No one assigned

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions