Skip to content
This repository has been archived by the owner on May 6, 2020. It is now read-only.

Match Python API in JavaScript inline script #125

Open
smathot opened this issue Mar 3, 2019 · 2 comments
Open

Match Python API in JavaScript inline script #125

smathot opened this issue Mar 3, 2019 · 2 comments
Assignees
Projects

Comments

@smathot
Copy link
Collaborator

smathot commented Mar 3, 2019

Ideally, we would expose an API in JavaScriptWorkspace that fully matches the Python API. I believe that this should be possible, although I'm not sure about the best implementation yet. We could change the current Canvas object (and others), or we could implement adapters that make these objects behave more like their Python counterparts. I looked into decorators to mimic the **style_args implementation, and it strikes me that we could do much the same in JavaScript.

In other words, I would like the following to work in an inline_javascript item.

c = new Canvas() // also acceptable: `Canvas()`
c.rect(0, 0, 100, 100, color="red")
c.show()

The Python API is quite elaborate, and we wouldn't necessarily need to implement all of it immediately. But Canvas, Keyboard, and Mouse would be very useful to start with.

@smathot smathot added this to To do in OSWeb 1.4 via automation Mar 3, 2019
@dschreij
Copy link
Collaborator

dschreij commented Mar 3, 2019

It should mostly possible. Instead of **style_args, one could use the JavaScript spread operator ... which is only available from ES7 or something onwards.
The only culprit remains the sleep() function again. This can nowadays be solved by using async functions, but then users have to explicitly use the await keyword, i.e. await sleep(1000) to make it work, and I don't know if this can be done from inside the eval() function...

@smathot
Copy link
Collaborator Author

smathot commented Mar 4, 2019

It should mostly possible. Instead of **style_args, one could use the JavaScript spread operator ... which is only available from ES7 or something onwards.

That might be an option then. If it makes life much easier, I don't mind if this comes at the expense of compatibility with older browsers, as long as we keep track of which browsers are supported.

The only culprit remains the sleep() function again. This can nowadays be solved by using async functions, but then users have to explicitly use the await keyword, i.e. await sleep(1000) to make it work, and I don't know if this can be done from inside the eval() function...

I was thinking about that too. Let's be pragmatic here, and focus on those things that are 1) doable and 2) useful. The clock object may only satisfy 2.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
OSWeb 1.4
  
To do
Development

No branches or pull requests

2 participants