Skip to content

kill stores.runtimeLoaded and many other stores#850

Merged
antocuni merged 20 commits into
mainfrom
antocuni/kill-runtime-global-store
Oct 17, 2022
Merged

kill stores.runtimeLoaded and many other stores#850
antocuni merged 20 commits into
mainfrom
antocuni/kill-runtime-global-store

Conversation

@antocuni

@antocuni antocuni commented Oct 13, 2022

Copy link
Copy Markdown
Contributor

As the title stays, the main goal of the branch is to kill the infamous runtimeLoaded global store and all the complications, problems and bugs caused by the fact that in many places we needed to ensure/wait that the global runtime was properly set before being able to execute code.

The core idea is that runtime is never a global object and that it's passed around explicitly, which means that when a function receives it, it is guaranteed to be initialized&ready.

This caused a bit of complications in pybutton.ts, pyinputbox.ts and pyrepl.ts, because they indirectly want to call runtime.run from connectedCallback, which is the only place where we cannot explicitly pass the runtime because it's automatically called by the browser.
But also, it is also a sign of a bad design, because it were entirely possible that connectedCallback was called before the runtime was ready, which probably caused many bugs, see e.g. #673 and #747.

The solution to is use dependency injection and create the class later on: so instead of having a global PyButton class which relies on a global runtime (whose state is uncertain) we have a make_PyButton function which takes a runtime and make a PyButton class which is tied to that specific runtime (whose state is certainly ready, because we call make_PyButton only when we know that the runtime is ready).
Similar for PyInputBox and PyRepl.

Other highlights: thanks to this, I could kill the also infamous runAfterRuntimeInitialized and a couple of smelly lines which used setTimeout to "wait" for the runtime.

While I was at it, I also called a lot of other stores which were completely unused and where probably leftovers from a past universe.

Note for reviewers: the bare diff is bigger than it should, because the majority of code in pyinputbox.ts, pybutton.ts and pyrepl.ts was indented by one level, without actually touching it. In order to minimize the diff and concentrate to the actual changes, I suggest to either review commits one by one (they are all nicely self-contained) or to use the "hide whitespace" option in the "Files changed" tab.

…nfused with .evaluate(). Instead, introduce a function with a similar behavior in Runtime.runButDontRaise, which is ugly as well and should be killed, but that's for another refactoring
…ing the PyButton class at startup, we create it only after we have the runtime. Note: the old code should be indented, but I didn't do it in this commit to minimize the diff
…since now the class definitions are enclosed inside a function
… sure that the runtime is ready when we execute this code
…e_PyRepl function in the same style as make_PyButton & co. The actual code of PyRepl was not touched at all, this commit just re-indents it
…the places which needs the runtime automatically get it only when it's ready 🎉🎉🎉
@antocuni antocuni changed the title WIP: kill stores.runtimeLoaded kill stores.runtimeLoaded and many other stores Oct 13, 2022
@antocuni antocuni marked this pull request as ready for review October 13, 2022 09:44

@madhur-tandon madhur-tandon left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

LGTM, the suggestion for hide whitespace helped, thanks for that -- learnt something new.

Comment thread pyscriptjs/tests/unit/fakeruntime.ts Outdated
Comment thread pyscriptjs/src/stores.ts Outdated
Comment thread pyscriptjs/tests/unit/fakeruntime.ts Outdated
@antocuni antocuni merged commit beb3aa1 into main Oct 17, 2022
@antocuni antocuni deleted the antocuni/kill-runtime-global-store branch October 17, 2022 08:31
JeffersGlass pushed a commit to JeffersGlass/pyscript that referenced this pull request Oct 17, 2022
As the title stays, the main goal of the branch is to kill the infamous runtimeLoaded global store and all the complications, problems and bugs caused by the fact that in many places we needed to ensure/wait that the global runtime was properly set before being able to execute code.

The core idea is that runtime is never a global object and that it's passed around explicitly, which means that when a function receives it, it is guaranteed to be initialized&ready.

This caused a bit of complications in pybutton.ts, pyinputbox.ts and pyrepl.ts, because they indirectly want to call runtime.run from connectedCallback, which is the only place where we cannot explicitly pass the runtime because it's automatically called by the browser.
But also, it is also a sign of a bad design, because it were entirely possible that connectedCallback was called before the runtime was ready, which probably caused many bugs, see e.g. pyscript#673 and pyscript#747.

The solution to is use dependency injection and create the class later on: so instead of having a global PyButton class which relies on a global runtime (whose state is uncertain) we have a make_PyButton function which takes a runtime and make a PyButton class which is tied to that specific runtime (whose state is certainly ready, because we call make_PyButton only when we know that the runtime is ready).
Similar for PyInputBox and PyRepl.

Other highlights: thanks to this, I could kill the also infamous runAfterRuntimeInitialized and a couple of smelly lines which used setTimeout to "wait" for the runtime.

While I was at it, I also called a lot of other stores which were completely unused and where probably leftovers from a past universe.
JeffersGlass pushed a commit to JeffersGlass/pyscript that referenced this pull request Oct 31, 2022
As the title stays, the main goal of the branch is to kill the infamous runtimeLoaded global store and all the complications, problems and bugs caused by the fact that in many places we needed to ensure/wait that the global runtime was properly set before being able to execute code.

The core idea is that runtime is never a global object and that it's passed around explicitly, which means that when a function receives it, it is guaranteed to be initialized&ready.

This caused a bit of complications in pybutton.ts, pyinputbox.ts and pyrepl.ts, because they indirectly want to call runtime.run from connectedCallback, which is the only place where we cannot explicitly pass the runtime because it's automatically called by the browser.
But also, it is also a sign of a bad design, because it were entirely possible that connectedCallback was called before the runtime was ready, which probably caused many bugs, see e.g. pyscript#673 and pyscript#747.

The solution to is use dependency injection and create the class later on: so instead of having a global PyButton class which relies on a global runtime (whose state is uncertain) we have a make_PyButton function which takes a runtime and make a PyButton class which is tied to that specific runtime (whose state is certainly ready, because we call make_PyButton only when we know that the runtime is ready).
Similar for PyInputBox and PyRepl.

Other highlights: thanks to this, I could kill the also infamous runAfterRuntimeInitialized and a couple of smelly lines which used setTimeout to "wait" for the runtime.

While I was at it, I also called a lot of other stores which were completely unused and where probably leftovers from a past universe.
JeffersGlass pushed a commit to JeffersGlass/pyscript that referenced this pull request Nov 14, 2022
As the title stays, the main goal of the branch is to kill the infamous runtimeLoaded global store and all the complications, problems and bugs caused by the fact that in many places we needed to ensure/wait that the global runtime was properly set before being able to execute code.

The core idea is that runtime is never a global object and that it's passed around explicitly, which means that when a function receives it, it is guaranteed to be initialized&ready.

This caused a bit of complications in pybutton.ts, pyinputbox.ts and pyrepl.ts, because they indirectly want to call runtime.run from connectedCallback, which is the only place where we cannot explicitly pass the runtime because it's automatically called by the browser.
But also, it is also a sign of a bad design, because it were entirely possible that connectedCallback was called before the runtime was ready, which probably caused many bugs, see e.g. pyscript#673 and pyscript#747.

The solution to is use dependency injection and create the class later on: so instead of having a global PyButton class which relies on a global runtime (whose state is uncertain) we have a make_PyButton function which takes a runtime and make a PyButton class which is tied to that specific runtime (whose state is certainly ready, because we call make_PyButton only when we know that the runtime is ready).
Similar for PyInputBox and PyRepl.

Other highlights: thanks to this, I could kill the also infamous runAfterRuntimeInitialized and a couple of smelly lines which used setTimeout to "wait" for the runtime.

While I was at it, I also called a lot of other stores which were completely unused and where probably leftovers from a past universe.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

Archived in project

Development

Successfully merging this pull request may close these issues.

2 participants