Skip to content

Commit b0d576f

Browse files
Fix bindings in Storage
1 parent ed44142 commit b0d576f

File tree

3 files changed

+36
-2
lines changed

3 files changed

+36
-2
lines changed

src/WebStorageAPI/Storage.res

+2-2
Original file line numberDiff line numberDiff line change
@@ -5,14 +5,14 @@ Returns the name of the nth key, or null if n is greater than or equal to the nu
55
[Read more on MDN](https://developer.mozilla.org/docs/Web/API/Storage/key)
66
*/
77
@send
8-
external key: (storage, int) => string = "key"
8+
external key: (storage, int) => Null.t<string> = "key"
99

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

1717
/**
1818
Sets the value of the pair identified by key to value, creating a new key/value pair if none existed for key previously.

tests/WebStorageAPI/Storage__test.js

+20
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

tests/WebStorageAPI/Storage__test.res

+14
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
open WebAPI.Global
2+
open WebAPI.Storage
3+
4+
for i in 0 to localStorage.length - 1 {
5+
localStorage->key(i)->Null.getOr("nothing")->Console.log
6+
}
7+
8+
let item1 = localStorage->getItem("foo")->Null.getOr("nothing")
9+
10+
localStorage->setItem(~key="bar", ~value="...")
11+
12+
localStorage->removeItem("bar")
13+
14+
localStorage->clear

0 commit comments

Comments
 (0)