Skip to content
Permalink

Comparing changes

Choose two branches to see what’s changed or to start a new pull request. If you need to, you can also or learn more about diff comparisons.

Open a pull request

Create a new pull request by comparing changes across two branches. If you need to, you can also . Learn more about diff comparisons here.
base repository: karaxnim/karax
Failed to load repositories. Confirm that selected base ref is valid, then try again.
Loading
base: 1.3.2
Choose a base ref
...
head repository: karaxnim/karax
Failed to load repositories. Confirm that selected head ref is valid, then try again.
Loading
compare: 1.3.3
Choose a head ref
  • 2 commits
  • 3 files changed
  • 2 contributors

Commits on Nov 6, 2023

  1. feature suggestion: {.noredraw.} pragma (#277)

    * 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
    choltreppe authored Nov 6, 2023
    Copy the full SHA
    3665564 View commit details

Commits on Nov 9, 2023

  1. Update version number in nimble file

    1.3.2 did not have the correct version number in the nimble file
    geotre authored Nov 9, 2023
    Copy the full SHA
    d86349c View commit details
Showing with 28 additions and 4 deletions.
  1. +1 −1 karax.nimble
  2. +8 −0 karax/karax.nim
  3. +19 −3 karax/karaxdsl.nim
2 changes: 1 addition & 1 deletion karax.nimble
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# Package

version = "1.3.1"
version = "1.3.3"
author = "Andreas Rumpf"
description = "Karax is a framework for developing single page applications in Nim."
license = "MIT"
8 changes: 8 additions & 0 deletions karax/karax.nim
Original file line number Diff line number Diff line change
@@ -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.
22 changes: 19 additions & 3 deletions 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
@@ -44,6 +44,21 @@ proc toKstring(n: NimNode): NimNode =
proc newDotAsgn(tmp: NimNode, key: string, x: NimNode): NimNode =
result = newTree(nnkAsgn, newDotExpr(tmp, newIdentNode key), x)

proc handleNoRedrawPragma(call: NimNode, tmpContext, name, anon: NimNode): NimNode =
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:
hasNoRedrawPragma = true
anon.pragma.del(i)
break
if hasNoRedrawPragma:
return newCall(ident"addEventHandlerNoRedraw", tmpContext,
newDotExpr(bindSym"EventKind", name), anon)
result = call

proc tcall2(n, tmpContext: NimNode): NimNode =
# we need to distinguish statement and expression contexts:
# every call statement 's' needs to be transformed to 'dest.add s'.
@@ -94,8 +109,9 @@ proc tcall2(n, tmpContext: NimNode): NimNode =
if tmpContext == nil:
error "no VNode to attach the event handler to"
else:
result = newCall(evHandler(), tmpContext,
newDotExpr(bindSym"EventKind", n[0]), anon, ident("kxi"))
let call = newCall(evHandler(), tmpContext,
newDotExpr(bindSym"EventKind", n[0]), anon, ident("kxi"))
result = handleNoRedrawPragma(call, tmpContext, n[0], anon)
else:
result = n
of nnkVarSection, nnkLetSection, nnkConstSection: