Skip to content

Commit 6c782d4

Browse files
authored
Add localStorage commands and documentation for get_item function (#23)
This pull request adds support for reading values from local storage in addition to the existing functionality for writing and removing items. The primary change is the introduction of a new `get_item` command and its documentation. **Local Storage Enhancements:** * Added a new `get_item` command to the storage schema, allowing retrieval of a value by key from local storage, returning an empty string if the key does not exist. * Documented the new `get_item` function in `docs/api/storage.md`, including usage and return value details. --------- Co-authored-by: io-eric <io-eric@users.noreply.github.com>
1 parent a4b36eb commit 6c782d4

2 files changed

Lines changed: 10 additions & 0 deletions

File tree

docs/api/storage.md

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,15 @@ Saves a key-value pair to local storage.
1818
void set_item(webcc::string_view key, webcc::string_view value);
1919
```
2020
21+
### `get_item`
22+
23+
Reads a value from local storage by its key. Returns an empty string if the key
24+
does not exist.
25+
26+
```cpp
27+
webcc::string get_item(webcc::string_view key);
28+
```
29+
2130
### `remove_item`
2231

2332
Removes an item from local storage by its key.

schema.def

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -147,6 +147,7 @@ system|command|INIT_VISIBILITY_CHANGE|init_visibility_change||{ document.addEven
147147
# STORAGE (LocalStorage)
148148
# ------------------------------------------------------------------------------
149149
storage|command|SET_ITEM|set_item|string:key string:value|{ localStorage.setItem(key, value); }
150+
storage|command|GET_ITEM|get_item|string:key RET:string|{ const ret = localStorage.getItem(key) || ""; }
150151
storage|command|REMOVE_ITEM|remove_item|string:key|{ localStorage.removeItem(key); }
151152
storage|command|CLEAR|clear||{ localStorage.clear(); }
152153

0 commit comments

Comments
 (0)