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

feature suggestion: {.noredraw.} pragma #277

Merged
merged 6 commits into from
Nov 6, 2023
Merged

Conversation

choltreppe
Copy link
Contributor

@choltreppe choltreppe commented Nov 3, 2023

There is currently no easy way to surpress redraw just for one specific handler (probably because it isnt needed very often).

You can kxi.surpressRedraw = true inside your handler, but then there is no way to set it back afterwards.
The only way currently is using addEventListener manually, which isnt very elegant.

So I added addEventHandlerNoRedraw procs to karax.nim and the .noredraw. pragma to the dsl syntax.
Now you just need to do:

buildHtml(..):
...
  proc onclick {.noredraw.} =
    dostuff
...

or

proc onclick(e: Event, n: VNode) {.noredraw.} =
  dostuff

maybe this would be nice to have in the repo

break
if hasNoRedrawPragma:
result = newCall(ident"addEventHandlerNoRedraw", tmpContext,
newDotExpr(bindSym"EventKind", n[0]), anon)
Copy link
Collaborator

Choose a reason for hiding this comment

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

Remove the debugEcho calls and move the logic to a helper proc.

@geotre
Copy link
Collaborator

geotre commented Nov 3, 2023

You can kxi.surpressRedraw = true inside your handler, but then there is no way to set it back afterwards.

I've definitely used surpressRedraw in at least one of my projects without manually adding event handlers, I just have to figure out where

I do like this PR though, it seems less error prone than the global flag. Good work @choltreppe

@Araq Araq merged commit 3665564 into karaxnim:master Nov 6, 2023
1 check passed
daylinmorgan pushed a commit to daylinmorgan/karax that referenced this pull request Aug 28, 2024
* add {.noredraw.} pragma for event handlers

* put .noredraw. pragma handling in seperate proc

* refactor

* refactor

* Revert "refactor"

This reverts commit 0d4ce4b.

* use result for return
daylinmorgan pushed a commit to daylinmorgan/karax that referenced this pull request Sep 14, 2024
* add {.noredraw.} pragma for event handlers

* put .noredraw. pragma handling in seperate proc

* refactor

* refactor

* Revert "refactor"

This reverts commit 0d4ce4b.

* use result for return
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.

3 participants