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
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions karax/karax.nim
Original file line number Diff line number Diff line change
Expand Up @@ -829,6 +829,14 @@ proc addEventHandler*(n: VNode; k: EventKind; action: proc();
if not kxi.surpressRedraws: redraw(kxi)
addEventListener(n, k, wrapper)

proc addEventHandlerNoRedraw*(n: VNode; k: EventKind; action: EventHandler) =
addEventListener(n, k, action)

proc addEventHandlerNoRedraw*(n: VNode; k: EventKind; action: proc()) =
proc wrapper(ev: Event; n: VNode) =
action()
addEventListener(n, k, wrapper)

proc setOnHashChange*(action: proc (hashPart: cstring)) {.deprecated: "use setRenderer instead".} =
## Now deprecated, instead pass a callback to ``setRenderer`` that receives
## a ``data: RouterData`` parameter.
Expand Down
17 changes: 16 additions & 1 deletion karax/karaxdsl.nim
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@

import macros, vdom, compact, kbase
from strutils import startsWith, toLowerAscii
from strutils import startsWith, toLowerAscii, cmpIgnoreStyle

when defined(js):
import karax
Expand Down Expand Up @@ -96,6 +96,21 @@ proc tcall2(n, tmpContext: NimNode): NimNode =
else:
result = newCall(evHandler(), tmpContext,
newDotExpr(bindSym"EventKind", n[0]), anon, ident("kxi"))
# if has pragma .noredraw. surpress redraw during event
when defined(js):
if anon.pragma.kind == nnkPragma and len(anon.pragma) > 0:
var hasNoRedrawPragma = false
for i in 0 ..< len(anon.pragma):
# using anon because anon needs to get rid of the pragma
if anon.pragma[i].kind == nnkIdent and cmpIgnoreStyle(anon.pragma[i].strVal, "noredraw") == 0:
debugEcho "noredraw"
hasNoRedrawPragma = true
anon.pragma.del(i)
debugEcho anon.pragma.repr
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.

else:
result = n
of nnkVarSection, nnkLetSection, nnkConstSection:
Expand Down
Loading