Skip to article frontmatterSkip to article content
Site not loading correctly?

This may be due to an incorrect BASE_URL configuration. See the MyST Documentation for reference.

JS: Persistence

Persistence

An attribute with the flag SDF_PERSIST stays between two visits of the same browser. The framework holds no store of its own. It calls the four functions that gobj_start_up() receives, and the package ships a back end on the local storage.

Source code: src/gobj.js, src/dbsimple.js


The API of the framework

Each function accepts a string, a list of names or an object of names in keys.

gobj_save_persistent_attrs(gobj, keys)

Saves the attributes that keys names.

gobj_load_persistent_attrs(gobj, keys)

Loads the attributes that keys names.

gobj_remove_persistent_attrs(gobj, keys)

Deletes the attributes that keys names from the store.

gobj_list_persistent_attrs(gobj, keys)

Gives the attributes that the store holds.


The back end on the local storage

Give these four functions to gobj_start_up(), and the API above works on the local storage of the browser.

import {
    gobj_start_up,
    db_load_persistent_attrs,
    db_save_persistent_attrs,
    db_remove_persistent_attrs,
    db_list_persistent_attrs
} from "@yuneta/gobj-js";

gobj_start_up(
    settings,
    db_load_persistent_attrs,
    db_save_persistent_attrs,
    db_remove_persistent_attrs,
    db_list_persistent_attrs,
    command_parser,
    stats_parser
);

db_save_persistent_attrs(gobj, keys)

Writes the attributes to the local storage.

db_load_persistent_attrs(gobj, keys)

Reads the attributes from the local storage.

db_remove_persistent_attrs(gobj, keys)

Deletes the attributes from the local storage.

db_list_persistent_attrs(gobj, keys)

Gives the attributes that the local storage holds.


The three helpers below the back end are in kw helpers. A write that fails gives -1, so a caller sees the failure. The local storage of a browser has a limit of size, and a private window can refuse a write.