Persisted global stores for Alpine 3.x.

Related tags

Database fern
Overview

Help support the maintenance of this package by sponsoring me.

Fern

Persisted global stores for Alpine 3.x.

Installation

Since Fern directly extends the global Alpine object, the recommended installation methods are NPM or a module <script> tag.

NPM

Install Fern by running the following command:

npm install @ryangjchandler/fern

Inside of your main script, add the following code:

import Alpine from 'alpinejs'
import Fern from '@ryangjchandler/fern'

Alpine.plugin(Fern)

Alpine.start()

<script type="module">

Add the following <script> to the <head> of your document before including Alpine:

<script type="module">
    import Fern from 'https://cdn.jsdelivr.net/npm/@ryangjchandler/[email protected]/dist/module.esm.js'

    document.addEventListener('alpine:initializing', () => {
        window.Alpine.plugin(Fern)
    })
</script>

Usage

Fern adds a new persistedStore method to the global Alpine object. The method's definition and usage is identical to Alpine.store():

Alpine.plugin(Fern)

Alpine.persistedStore('counter', 0)

Alpine.start()

Creating a persistedStore will register a normal store with Alpine and keep track of all changes, pushing them back to localStorage when updated.

<div x-data>
    <p x-text="$store.counter"></p>
    <button x-on:click="$store.counter++">Increment</button>
</div>

If you're using the <script type="module"> installation method, be sure to make your persistedStore calls after registering Fern.

    document.addEventListener('alpine:initializing', () => {
        window.Alpine.plugin(Fern)

        window.Alpine.persistedStore('counter', 0)
    })

Versioning

This projects follow the Semantic Versioning guidelines.

License

Copyright (c) 2021 Ryan Chandler and contributors

Licensed under the MIT license, see LICENSE.md for details.

You might also like...

Google-reviews-crawler - A simple Playwright crawler that stores Google Maps Place/Business reviews to a JSON file.

google-reviews-crawler A simple Playwright crawler that stores Google Maps Place/Business reviews to a JSON file. Usage Clone the repo, install the de

Oct 26, 2022

An SST app that stores the telemetry data collected by the SST CLI.

Telemetry An SST app that collects telemetry data from the SST CLI and sends the events to Amplitude. It also backs up the events to AWS S3. Architect

Jan 23, 2022

A simple single page web-app that stores, removes and edits books' names in the browser's local storage.

A simple single page web-app that stores, removes and edits books' names in the browser's local storage.

A simple single page web-app that stores, removes and edits books' names in the browser's local storage. Made with Webpack bundler

Apr 1, 2022

A database library stores JSON file for Node.js.

concisedb English | 简体中文 A database library stores JSON file for Node.js. Here is what updated every version if you want to know. API Document Usage B

Sep 4, 2022

A remote nodejs Cache Server, for you to have your perfect MAP Cache Saved and useable remotely. Easy Server and Client Creations, fast, stores the Cache before stopping and restores it again!

A remote nodejs Cache Server, for you to have your perfect MAP Cache Saved and useable remotely. Easy Server and Client Creations, fast, stores the Cache before stopping and restores it again!

remote-map-cache A remote nodejs Cache Server, for you to have your perfect MAP Cache Saved and useable remotely. Easy Server and Client Creations, fa

Oct 31, 2022

This Project is basically provides a cloud based solution for the medical stores so they can manage their inventory, expiry, billbook & credits on a single platform

This Project is basically provides a cloud based solution for the medical stores so they can manage their inventory, expiry, billbook & credits on a single platform

Jul 11, 2022

Recoil Sync stores for Next.js

recoil-sync-next Recoil Sync stores for Next.js Features URL Persistence Syncing an atom with the browser URL. Session Storage Persistence Synced with

Dec 28, 2022

A lightweight abstraction between Svelte stores and Chrome extension storage.

Svelte Chrome Storage A lightweight abstraction between Svelte stores and Chrome extension storage. This library makes data synchronization of backgro

Nov 15, 2022

A JavaScript library stores the form-data to the localstorage so you don't have to fill the form again.

A JavaScript library stores the form-data to the localstorage so you don't have to fill the form again.

form-storage A JavaScript library stores the form-data to the localstorage so you don't have to fill the form again. Installation via npm npm install

Dec 10, 2022

This monorepo stores all code and assets of all projects with which we develop regels.overheid.nl

Welcome Introduction In 2021 Utrecht started developing the Virtual Income Desk with Open Rules. An initiative with the aim for citizens to always and

Dec 8, 2022

This is a project that add, stores and deletes current book in the library

Project Name Awesome books: with ES6 Description the project. In this project, I restructured my Awesome books app code. The goal was to make it more

Nov 11, 2022

Global HTTP/HTTPS proxy agent configurable using environment variables.

global-agent Global HTTP/HTTPS proxy configurable using environment variables. Usage Setup proxy using global-agent/bootstrap Setup proxy using bootst

Dec 20, 2022

Add focal point alignment of images to your Alpine 3.x components with a custom directive.

Alpine Focal Add focal point alignment of images to your Alpine 3.x components with a custom directive. This package only supports Alpine v3.x. About

Oct 12, 2021

Jquery.Circle.js - Circle is a Javascript global-menu library for jQuery.

Circle About Circle is a Javascript global-menu library for jQuery. Read more at the website: http://uc.gpgkd906.com/ Installation Just include the Ja

Jul 19, 2021

Solid.js library adding a services layer for global shared state.

Solid.js library adding a services layer for global shared state.

Solid Services Services are "global" objects useful for features that require shared state or persistent connections. Example uses of services might i

Dec 30, 2022

Create reusable components with Alpine JS reactivity 🦑

Apline JS Component Create reusable HTML components sprinkled with Alpine JS reactive data 🧁 Example 👀 Page We can render on page components by usin

Dec 29, 2022

Vue2.x plugin to create scoped or global shortcuts. No need to import a vue component into the template.

vue2-shortcut Vue2.x plugin to create scoped or global shortcuts. No need to import a vue component into the template. Install $ npm install --save vu

Aug 14, 2022

An event emitter that allows you to manage your global state

Thor Event Emitter Event emitter to manage your state. An event emitter that allows you to manage your global state. Instead of using global giant obj

Apr 18, 2022
Comments
  • Add session storage support with function option

    Add session storage support with function option

    Great work dude. I've never done a pull request before, so please let me know if I did anything wrong in this process, just edited the file on github. Worked on a separate thing I was playing with. Seems this could be the cleanest way to add session storage support without breaking anything for anyone else and keeping it DRY.

    opened by ekwoka 7
  • Support get

    Support get

    Had some issues with computed metrics inside persistedStores. Alpine Stores support functions and getters, but persisted stores would break getters (did not check functions as it would make more sense to put functions in a different namespace as opposed to within a store) by overwriting the getter with the last saved data.

    This change ensures getters are not overwritten by stored data. It does flip the direction of the "diff" content, which I don't believe should have any unintended side effects

    opened by ekwoka 0
Releases(v0.1.0)
Owner
Ryan Chandler
Ryan Chandler
A wrapper for abstract-leveldown compliant stores, for Node.js and browsers.

levelup Table of Contents Click to expand levelup Table of Contents Introduction Supported Platforms Usage API Special Notes levelup(db[, options[, ca

Level 4k Jan 9, 2023
mini-stores - 小程序多状态管理库,支持微信/支付宝/钉钉/百度/字节/QQ/京东等小程序,小巧高性能,新老项目都可使用。

mini-stores - 小程序多状态管理 前言 安装 API 使用 创建store 创建页面 创建组件 视图上使用 更新状态 使用建议 快捷链接 前言 公司好几款产品使用钉钉小程序开发,和其他平台小程序一样,都没有官方实现的状态管理库,用过redux、vuex、mobx等状态管理库的前端小伙伴都

linjc 104 Dec 27, 2022
A database library stores JSON file for Node.js.

concisedb English | 简体中文 A database library stores JSON file for Node.js. Here is what updated every version if you want to know. API Document Usage B

LKZ烂裤子 3 Sep 4, 2022
Eine einfache Möglichkete Tailwindcss und Alpine.js mit REDAXO zu nutzen

TAR - Tailwindcss - Alpine.js - REDAXO Eine einfache Möglichkeit REDAXO mit Tailwindcss zu nutzen Installation: yarn install oder npm install Die gewü

Thorben 3 Feb 24, 2022
Grupprojekt för kurserna 'Javascript med Ramverk' och 'Agil Utveckling'

JavaScript-med-Ramverk-Laboration-3 Grupprojektet för kurserna Javascript med Ramverk och Agil Utveckling. Utvecklingsguide För information om hur utv

Svante Jonsson IT-Högskolan 3 May 18, 2022
Hemsida för personer i Sverige som kan och vill erbjuda boende till människor på flykt

Getting Started with Create React App This project was bootstrapped with Create React App. Available Scripts In the project directory, you can run: np

null 4 May 3, 2022
Kurs-repo för kursen Webbserver och Databaser

Webbserver och databaser This repository is meant for CME students to access exercises and codealongs that happen throughout the course. I hope you wi

null 14 Jan 3, 2023
Realm is a mobile database: an alternative to SQLite & key-value stores

Realm is a mobile database that runs directly inside phones, tablets or wearables. This project hosts the JavaScript versions of Realm. Currently we s

Realm 5.1k Jan 3, 2023
A wrapper for abstract-leveldown compliant stores, for Node.js and browsers.

levelup Table of Contents Click to expand levelup Table of Contents Introduction Supported Platforms Usage API Special Notes levelup(db[, options[, ca

Level 4k Jan 9, 2023
mini-stores - 小程序多状态管理库,支持微信/支付宝/钉钉/百度/字节/QQ/京东等小程序,小巧高性能,新老项目都可使用。

mini-stores - 小程序多状态管理 前言 安装 API 使用 创建store 创建页面 创建组件 视图上使用 更新状态 使用建议 快捷链接 前言 公司好几款产品使用钉钉小程序开发,和其他平台小程序一样,都没有官方实现的状态管理库,用过redux、vuex、mobx等状态管理库的前端小伙伴都

linjc 104 Dec 27, 2022