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

refactor: Improve communication between plugin and ui & bundle ui #36

Merged
merged 5 commits into from
Oct 2, 2021
Merged

refactor: Improve communication between plugin and ui & bundle ui #36

merged 5 commits into from
Oct 2, 2021

Conversation

agerardin
Copy link
Contributor

The plugin is relying on a timer that triggers a full refresh every second.
This impacts UI responsiveness and increase resource usage.
The UI script also uses a timer to figure out when the d3 library has finished loading.

This commit addresses both issues by:

  • Replacing the first timer by a poll mechanism. When the API notifies
    on a change, a model change is added to a queue. The ui checks the queue
    for new updates and apply them. This allows for a cleaner execution model
    and improves responsiveness.

  • Using extra-scripts to bundle ui & d3 with webpack. This removes the
    second timer and have the side benefit of reducing the plugin's size by
    5 due to treeshaking.

…endencies

The plugin is relying on a timer that triggers a full refresh every second.
This impacts UI responsiveness and increase resource usage.
The UI script also uses a timer to figure out when the d3 library has finished loading.

This commit addresses both issues by:

* Replacing the first timer by a poll mechanism. When the API notifies
  on a change, a model change is added to a queue. The ui checks the queue
  for new updates and apply them. This allows for a cleaner execution model
  and improves responsiveness.

* Using extra-scripts to bundle ui & d3 with webpack. This removes the
  second timer and have the side benefit of reducing the plugin's size by
  5 due to treeshaking.
@treymo
Copy link
Owner

treymo commented Sep 24, 2021

Thank you for this @agerardin!! I'll review this today or tomorrow and get it merged

@treymo treymo self-assigned this Sep 24, 2021
@treymo treymo added the enhancement New feature or request label Sep 24, 2021
@treymo treymo linked an issue Sep 24, 2021 that may be closed by this pull request
Copy link
Owner

@treymo treymo left a comment

Choose a reason for hiding this comment

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

I'm testing this out locally and seeing: Module not found: Error: Can't resolve 'd3' in '$HOME/dev/joplin-graph-view/src/ui'

I think the d3.js file should remain checked into the repo. Are you installing that dependency somewhere outside the repository on your machine?

@agerardin
Copy link
Contributor Author

Hello! I have added d3 as a dependency in package.json. ui/index.js is declared as an extraScript in plugin.config.json so it will be bundled by webpack in a separate entry. rerun npm install should get rid of the error.

src/index.ts Outdated Show resolved Hide resolved
src/index.ts Show resolved Hide resolved
Copy link
Owner

@treymo treymo left a comment

Choose a reason for hiding this comment

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

Just a couple minor questions, but this is a great improvement! Thank you for bringing some real JS experience to the project haha

@agerardin
Copy link
Contributor Author

Hello! I have updated with your remarks.
The promise callback mechanism is still quite hacky but that's the best I could come out with using the current webviewAPI. I am delving into Joplin's plugin code to see how to do better but it will take some more time.

@agerardin agerardin requested a review from treymo October 2, 2021 13:40
@treymo treymo merged commit 293eece into treymo:master Oct 2, 2021
@agerardin
Copy link
Contributor Author

To follow up on this, I was looking for a mechanism to send message from the plugin to the view rather than polling the plugin for changes. This is currently not implemented. I have a pull request ready for enabling push notifications so I will start discussing it with Joplin's contributors. Until this happens, the current method will do!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Draw only once for better exploration
2 participants