1. localStorage simplest

local-storage read only during initial and only render, does not track the changes.

Has to produce 12πŸ’


        <custom-element tag="dce-1" hidden="">
            {//slice/fruits/text()}
            <slot>πŸ€”</slot>
            <local-storage key="cherries" slice="fruits"></local-storage>
        </custom-element>
        <dce-1>πŸ’</dce-1>
    
12πŸ’

2. localStorage basket JSON

local-storage tracks changes

Click the fruits button to add into cart


        <custom-element tag="dce-2" hidden="">
            <template>
                <local-storage key="basket" slice="basket" live="" type="json"></local-storage>
                <xhtml:table xmlns:xhtml="http://www.w3.org/1999/xhtml">
                    <xhtml:tbody>
                        <xsl:for-each select="//basket/@*">
                            <xhtml:tr>
                                <xhtml:th> {name()} </xhtml:th>
                                <xhtml:td> {.}      </xhtml:td>
                            </xhtml:tr>
                        </xsl:for-each>
                    </xhtml:tbody>
                    <xhtml:tfoot>
                        <xhtml:tr>
                            <xhtml:td><slot>πŸ€”</slot></xhtml:td>
                            <xhtml:th> {sum(//slice/basket/@*)} </xhtml:th>
                        </xhtml:tr>
                    </xhtml:tfoot>
                </xhtml:table>
            </template>
        </custom-element>
        <dce-2>πŸ›’total</dce-2>
    
cherries 12
lemons 1
πŸ›’total 13
localStorage content

The demo should display count 1πŸ‹ and 12πŸ’ initially. The value in localStorage is incremented when clicked on matching button

Click to add the localStorage value
keyvalue
lemons1
basket{"cherries":12,"lemons":1}
apple
cherries12
banana