ftd.local_storage
simplifies the process of working with Local Storage in your fastn
projects.
It functions as a wrapper around the browser's Local Storage API, facilitating the storage and retrieval of data in the client-side storage of your users' web browsers.
ftd.local_storage
also provides namespacing for local storage, which prevents naming collisions when multiple packages in your project are using local storage.-- ftd.text: Save name
color: $inherited.colors.text-strong
$on-click$: save-data()
-- void save-data():
ftd.local_storage.set("name", "Universe")
-- string $name: World
-- ftd.text: $name
color: $inherited.colors.text
-- ftd.text: Get name
color: $inherited.colors.text-strong
$on-click$: get-data($a = $name)
-- void get-data(a):
string $a:
name = ftd.local_storage.get("name", "Universe");
__args__.a.set(name || "Empty");
Remove specific data entries using ftd.local_storage.delete(key). This function makes cleaning up data in Local Storage easy.
In the example below, when you click on the 'Get name' button, if the name has not been deleted yet and was previously set using the ftd.local_storage.set(k, v)
method, it will display that name.
-- string $name: World
-- ftd.text: $name
color: $inherited.colors.text
-- ftd.text: Get name
color: $inherited.colors.text-strong
$on-click$: get-data($a = $name)
-- ftd.text: Delete name
color: $inherited.colors.text-strong
$on-click$: $delete-data()
-- void get-data(a):
string $a:
name = ftd.local_storage.get("name", "Universe");
__args__.a.set(name || "Empty");
-- void delete-data(a):
string $a:
ftd.local_storage.delete("name")