Skip to content

Commit

Permalink
fix jsformdata (and also to trigger doc rebuilt after nim-lang/Nim#16999
Browse files Browse the repository at this point in the history
)
  • Loading branch information
timotheecour committed Mar 29, 2021
1 parent fb16554 commit 8f24a94
Showing 1 changed file with 9 additions and 11 deletions.
20 changes: 9 additions & 11 deletions src/fusion/js/jsformdata.nim
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,15 @@
when not defined(js):
{.fatal: "Module jsformdata is designed to be used with the JavaScript backend.".}

runnableExamples("-r:off"):
let data: FormData = newFormData()
data["key0"] = "value0".cstring
data.add("key1".cstring, "value1".cstring)
data.delete("key1")
doAssert data.hasKey("key0")
doAssert data["key0"] == "value0".cstring
data.clear()

type FormData* = ref object of JsRoot ## FormData API.

func newFormData*(): FormData {.importjs: "new FormData()".}
Expand Down Expand Up @@ -45,14 +54,3 @@ func `[]`*(this: FormData; name: cstring): cstring {.importjs: "#.get(#)".}
func clear*(this: FormData) {.importjs:
"(() => { const frmdt = #; Array.from(frmdt.keys()).forEach((key) => frmdt.delete(key)) })()".}
## Convenience func to delete all items from `FormData`.


runnableExamples:
if defined(fusionJsFormdataTests):
let data: FormData = newFormData()
data["key0"] = "value0".cstring
data.add("key1".cstring, "value1".cstring)
data.delete("key1")
doAssert data.hasKey("key0")
doAssert data["key0"] == "value0".cstring
data.clear()

0 comments on commit 8f24a94

Please sign in to comment.