be-persistent

be-persistent is a behavior/decorator that provides persistence storage to native DOM and custom elements.

Usage no npm install needed!

<script type="module">
  import bePersistent from 'https://cdn.skypack.dev/be-persistent';
</script>

README

be-persistent

be-persistent is a behavior/decorator alternative to purr-sist.

Example 1: Default settings;

<input be-persistent>

What this does:

Stores input's value in session storage (key is based on location within the DOM).

The syntax above is short-hand for:

<input be-persistent='{
    "what":{
        "value": true
    },
    "when":{
        "input": true
    },
    "where":{
        "sessionStorage": true,
        "autogenId": true,
    },
    "restoreIf":{
        "always": true,
    }
}'>

Example 2: Store to IDB

<input be-persistent='{
    "where":{
        "idb": true
    }
}'>

On refreshing the browser, the input's value is retained.

Example tbd: Criteria [TODO]

<input be-persistent='{
    "restoreIf":{
        "value":{
            "eq": "defaultValue"
        }
    }
}'>

Example tbd: IBD [TODO]

<input be-persistent='{
    "what": {
        "value": "myInputValue"
    },
    "when": ["change"],
    "where": {
        "IBD":{
            "id": "...",
            "path": "a.b.c"
        }
    }
}'>

Example 3: Criteria