Directory

purr-sist - Vaadin Add-on Directory

Web component wrapper around persistence services purr-sist - Vaadin Add-on Directory
[![Published on webcomponents.org](https://img.shields.io/badge/webcomponents.org-published-blue.svg)](https://www.webcomponents.org/element/purr-sist) # purr-sist purr-sist-* are web component wrappers around various services used to persist (history.)state. What follows purr-sist- indicates where the state is persisted. For example, purr-sist-myjson persists state to the [myjson.com](http://myjson.com/) api service. The service allows anyone to save and update a JSON document, with zero setup steps. See discussion below about the pro's and significant con's of this service. purr-sist-idb persists state to the local indexed db for offline storage (and potentially cross window state management). **NB**: Quite a bit of the functionality described here overlaps significantly with the slightly better known [Polymer data elements](https://www.webcomponents.org/element/@polymer/app-storage), which I remembered about recently. At this point, there's no doubt those components support useful features not found here for now (like orchestrating data moving as the user's status switches between offline and online mode). ## Syntax Reference ## Basic Syntax purr-sist has two modes: ```html ``` The first tag ("read") above will only read from the remote store. The second will only write. One tag cannot serve both roles. The write mode tag cannot retrieve existing data on its own. It must be passed a record (if one exists) from the read mode tag. If you place write mode tag on the page with the new attribute: ```html ``` since no "store-id" is specified, a new "{}" record will be created on initial load. If you inspect the element, you will see the id of that new record reflected to the element with attribute "store-id". Once you have the id, you *could* set it / hardcode it in your markup (after removing the create attribute). ```html ``` As we will see, this can be useful in some cases, particularly for "master lists". ## Master Index purr-sist adds some fundamental support for scaling large saves, so they can be broken down somewhat. First, there is a property, guid, which stands for "globally unique identifier." There are [many](https://duckduckgo.com/?q=online+guid+generator&t=h_&ia=web) [tools](https://marketplace.visualstudio.com/search?term=guid&target=VSCode&category=All%20categories&sortBy=Relevance) that can generate these for you. Second, there's a property "master-list-id" which specifies the id of a DOM element outside any Shadow DOM. That DOM element should also be a purr-sist element, which serves as the master list indexer. It contains a lookup between the guid, hardcoded in the markup (or initialization code), and the id defined by the remote datastore (myjson.com in this case). So the markup can look like: ```html ... #ShadowDOM #EndShadowDOM ``` Note the value of the master-list-id attribute starts with a /. This is to explicitly state that the id is expected to be found outside any Shadow DOM. The ability to reference a master list sitting inside some Shadow DOM realm is not currently supported. # Examples Part A -- persisting to myjson.com ## Why myjson.com? myjson.com is easy as pie to use. It is so simple, in fact, that it kind of mirrors the (overly?) simple api we get with the browser's history api. One of the objectives of this component is to provide persistence of the history.state object, so myjson.com would appear to have no "impedence mismatch" with the window.history.[push|replace]State calls, which probably is not a very flattering thing to say about the window.history api. In addition, myjson.com requires no account set up, so it just works, with zero fuss. ## What's the problem with myjson.com? Due to the extremely trusting nature of myjson.com, it would be quite dangerous to use in a production setting, so use of this service should be restricted to storing and retrieving harmless data, such as URL paths or public data, or for academic / prototyping purposes. myjson.com is similar, but not nearly as powerful, as other, far more robust solutions like [Firebase](https://firebase.google.com/docs/database/rest/save-data) (or mongoDB, or countless other solutions). Firebase's ability to save to a path, and not overwrite the entire record, is certainly quite appealing. I'm 99% certain that using Firebase instead of myjson.com would reduce the packet size in a fairly significant way. But I would argue that the approach of creating a master list, detailed below, helps whether you are using Firebase or myjson.com. ## Update pieces of the remote store To send a new object to the remote store, replacing the old one, use the newVal property: ```JavaScript const myValue = {chairman: 'meow'}; document.querySelector('purr-sist-foo').newVal = {'kitty': myValue} ``` ## Example A.1 -- Time travel support (aka back button) [See it in action](https://bahrus.github.io/purr-sist-demos/Example3.html) Data flow is **almost** unidirectional (see tag p-u for bad code smell exception). Markup shown below. ```html Example 3
```
View on NPM
View on GitHub

purr-sist version 0.0.0
### Dependencies

purr-sist version 0.0.1
### Dependencies * xtal-latx#0.0.44

purr-sist version 0.0.2
### Dependencies * xtal-latx#0.0.44

purr-sist version 0.0.3
### Dependencies * xtal-latx#0.0.44

purr-sist version 0.0.4
### Dependencies * xtal-latx#0.0.44

purr-sist version 0.0.5
### Dependencies * xtal-latx#0.0.44

purr-sist version 0.0.6
### Dependencies * xtal-latx#0.0.44

purr-sist version 0.0.7
### Dependencies * xtal-latx#0.0.44

purr-sist version 0.0.8
### Dependencies * xtal-latx#0.0.44

purr-sist version 0.0.10
### Dependencies * xtal-latx#0.0.46

purr-sist version 0.0.9
### Dependencies * xtal-latx#0.0.46

purr-sist version 0.0.11
### Dependencies * xtal-latx#0.0.46

purr-sist version 0.0.12
### Dependencies * xtal-latx#0.0.46

purr-sist version 0.0.13
### Dependencies * xtal-latx#0.0.46

purr-sist version 0.0.14
### Dependencies * xtal-latx#0.0.46

purr-sist version 0.0.15
### Dependencies * xtal-latx#0.0.46

purr-sist version 0.0.16
### Dependencies * xtal-latx#0.0.46

purr-sist version 0.0.17
### Dependencies * xtal-latx#0.0.46

purr-sist version 0.0.18
### Dependencies * xtal-latx#0.0.46

purr-sist version 0.0.19
### Dependencies * xtal-latx#0.0.46

purr-sist version 0.0.20
### Dependencies * xtal-latx#0.0.46

purr-sist version 0.0.21
### Dependencies * xtal-latx#0.0.46

purr-sist version 0.0.22
### Dependencies * xtal-latx#0.0.46

purr-sist version 0.0.23
### Dependencies * xtal-latx#0.0.46

purr-sist version 0.0.24
### Dependencies * xtal-latx#0.0.46

purr-sist version 0.0.25
### Dependencies * xtal-latx#0.0.46

purr-sist version 0.0.26
### Dependencies * xtal-latx#0.0.82

purr-sist version 0.0.27
### Dependencies * xtal-latx#0.0.82

purr-sist version 0.0.28
### Dependencies * xtal-latx#0.0.82

purr-sist version 0.0.29
### Dependencies * xtal-latx#0.0.82

purr-sist version 0.0.30
### Dependencies * xtal-latx#0.0.82

purr-sist version 0.0.31
### Dependencies * xtal-latx#0.0.82

purr-sist version 0.0.32
### Dependencies * xtal-latx#0.0.82

purr-sist version 0.0.33
### Dependencies * xtal-latx#0.0.85 * idb-keyval#3.1.0

purr-sist version 0.0.34
### Dependencies * xtal-latx#0.0.85 * idb-keyval#3.1.0

purr-sist version 0.0.35
### Dependencies * xtal-latx#0.0.85 * idb-keyval#3.1.0

purr-sist version 0.0.36
### Dependencies * xtal-latx#0.0.85 * idb-keyval#3.1.0

purr-sist version 0.0.37
### Dependencies * xtal-element#0.0.42 * idb-keyval#3.1.0

purr-sist version 0.0.38
### Dependencies * xtal-element#0.0.42 * idb-keyval#3.1.0

purr-sist version 0.0.39
### Dependencies * xtal-element#0.0.45 * idb-keyval#3.2.0

purr-sist version 0.0.40
### Dependencies * xtal-element#0.0.48 * idb-keyval#3.2.0

purr-sist version 0.0.41
### Dependencies * xtal-element#0.0.48 * idb-keyval#3.2.0

purr-sist version 0.0.42
### Dependencies * xtal-element#0.0.48 * idb-keyval#3.2.0

purr-sist version 0.0.43
### Dependencies * xtal-element#0.0.48 * idb-keyval#3.2.0

purr-sist version 0.0.44
### Dependencies * xtal-element#0.0.48 * idb-keyval#3.2.0

purr-sist version 0.0.45
### Dependencies * xtal-element#0.0.48 * idb-keyval#3.2.0

purr-sist version 0.0.46
### Dependencies * xtal-element#0.0.48 * idb-keyval#3.2.0

purr-sist version 0.0.47
### Dependencies * xtal-element#0.0.48 * idb-keyval#3.2.0

purr-sist version 0.0.48
### Dependencies * xtal-element#0.0.48 * idb-keyval#3.2.0

purr-sist version 0.0.49
### Dependencies * xtal-element#0.0.48 * idb-keyval#3.2.0

purr-sist version 0.0.50
### Dependencies * xtal-element#0.0.48 * idb-keyval#3.2.0

purr-sist version 0.0.51
### Dependencies * xtal-element#0.0.54 * idb-keyval#3.2.0

purr-sist version 0.0.52
### Dependencies * xtal-element#0.0.56 * trans-render#0.0.106 * idb-keyval#3.2.0

purr-sist version 0.0.53
### Dependencies * xtal-element#0.0.57 * trans-render#0.0.107 * idb-keyval#3.2.0

purr-sist version 0.0.54
### Dependencies * xtal-element#0.0.58 * trans-render#0.0.110 * idb-keyval#3.2.0

purr-sist version 0.0.55
### Dependencies * xtal-element#0.0.58 * trans-render#0.0.110 * idb-keyval#3.2.0

purr-sist version 0.0.56
### Dependencies * xtal-element#0.0.58 * trans-render#0.0.110 * idb-keyval#3.2.0

purr-sist version 0.0.57
### Dependencies * xtal-element#0.0.58 * trans-render#0.0.110 * idb-keyval#3.2.0