Skip to content

Fix bindings in Storage #39

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

Merged
merged 1 commit into from
Jan 2, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
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
4 changes: 2 additions & 2 deletions src/WebStorageAPI/Storage.res
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,14 @@ Returns the name of the nth key, or null if n is greater than or equal to the nu
[Read more on MDN](https://developer.mozilla.org/docs/Web/API/Storage/key)
*/
@send
external key: (storage, int) => string = "key"
external key: (storage, int) => Null.t<string> = "key"

/**
Returns the current value associated with the given key, or null if the given key does not exist.
[Read more on MDN](https://developer.mozilla.org/docs/Web/API/Storage/getItem)
*/
@send
external getItem: (storage, string) => string = "getItem"
external getItem: (storage, string) => Null.t<string> = "getItem"

/**
Sets the value of the pair identified by key to value, creating a new key/value pair if none existed for key previously.
Expand Down
20 changes: 20 additions & 0 deletions tests/WebStorageAPI/Storage__test.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

14 changes: 14 additions & 0 deletions tests/WebStorageAPI/Storage__test.res
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
open WebAPI.Global
open WebAPI.Storage

for i in 0 to localStorage.length - 1 {
localStorage->key(i)->Null.getOr("nothing")->Console.log
}

let item1 = localStorage->getItem("foo")->Null.getOr("nothing")

localStorage->setItem(~key="bar", ~value="...")

localStorage->removeItem("bar")

localStorage->clear
Loading