todoapp: use local storage properly

This commit is contained in:
Andreas Rumpf 2017-04-22 10:45:42 +02:00
commit 6aa87e4b81
3 changed files with 40 additions and 26 deletions

View file

@ -21,3 +21,5 @@ proc isInt*(s: cstring): bool {.asmNoStackFrame.} =
asm """
return s.match(/^[0-9]+$/);
"""
proc parseInt*(s: cstring): int {.importcpp: "parseInt(#, 10)", nodecl.}

10
src/localstorage.nim Normal file
View file

@ -0,0 +1,10 @@
## Karax -- Single page applications for Nim.
## This module contains wrappers for the HTML 5 local storage.
proc getItem*(key: cstring): cstring {.importc: "localStorage.getItem"}
proc setItem*(key, value: cstring) {.importc: "localStorage.setItem"}
proc hasItem*(key: cstring): bool {.importcpp: "(localStorage.getItem(#) !== null)".}
proc clear*() {.importc: "localStorage.clear"}
proc removeItem*(key: cstring) {.importc: "localStorage.removeItem".}