1.1.1 • Published 4 years ago

undying v1.1.1

Weekly downloads
5
License
ISC
Repository
-
Last release
4 years ago

undying 🧟🧛🧟👻🧛🧟

Tiny & fast "auto-save" data objects to local storage or session storage

Pretty small, eh?

Usage

import { undying } from 'undying';


const defaultValues = {
    favouriteColor: 'blue',
};

const undyingObject = undying('storage-key', defaultValues);
// If exists on local storage, ignores default values,
// If does not exists, creates it with default values


undyingObject.favouriteColor = 'red';
// async flushed to local storage.

An undying object is a JSON-format object proxy, flushing changes into localStorage. When an undying object's property is assigned with another object (or array), the actual saved value is an undying object. This means mutations in the object's inner tree and even array mutations are caught and saved into the localStorage.

Every change triggers an async flush - meaning that multiple changes wait until the end of the current execution stack and the store occurs only once in a dedicated microtask.

Session storage

import { undying } from 'undying';

const undyingData = undying.session('storage-key', {});

Watching changes

import { undying } from 'undying';
const undyingObject = undying('user-defaults'); // defaults to an empty object, otherwise last stored data

undying.observe(undyingObject, (value) => {
    // value is the whole tree data
});
1.1.1

4 years ago

1.1.0

4 years ago

1.0.3

4 years ago

1.0.2

4 years ago

1.0.1

4 years ago

1.0.0

4 years ago