effector-localstorage

Tiny and elegant module for Effector to keep store state in localStorage and synchronize changes between browser tabs

MIT License

Downloads
3.7K
Stars
31
Committers
6
effector-localstorage - v1.0.0 Latest Release

Published by ilyalesik over 1 year ago

This is completely full rewrite of the package.

Original sources was made 4 years back, and become obsolete with time (though original code is still working as intended, thanks for simplicity and effector's back compatibility).

Instead of two modules (main and sync) there is a single module now, which supports synchronization as well. It is slightly bigger (few bytes) than original main module from previous version, and less, than original sync module from previous version. Original sources are kept in old directory for reference (because different versions of size-limit shows different sizes for same code).

Main reason for rewrite — is to change API.

Two different packages for localStorage (effector-localstorage and effector-storage) confuses users, sometimes someone asks in effector's community chat, which one should they use. Well, both packages are good, but effector-localstorage is tiny and with bare-minimum functionality, while effector-storage is slightly bigger (around 1.5 kb for localStorage adapter), but with richer functionality.

And we decided to change effector-localstorage API so it become similar to effector-storage. So, you can use tiny package as long as it fits your requirements, and simply change import to start using rich functionality.

I love tiny packages, so I would not like to mark effector-localstorage as deprecated and obsolete.

So, meet second life of effector-localstorage with new API :)

effector-localstorage -

Published by ilyalesik almost 5 years ago

Store synchronization has been separated into the sync module:

import {createStore, createEvent} from 'effector'
import connectLocalStorage from "effector-localstorage/sync";

effector-localstorage - New feature: onChange method

Published by ilyalesik almost 5 years ago

New onChange method allow to subscribe on storage change event:

const setCounter = createEvent('set counter')

const counterLocalStorage = connectLocalStorage("counter")
  .onChange(setCounter) // call event on external storage change
effector-localstorage -

Published by ilyalesik almost 5 years ago

New feature:

init gets default value:

counterLocalStorage.init(0)

Fix error handling

In case of error onError was called, instead of errorHandler

Decreasing size

120B -> 111B

effector-localstorage - Add TS typings

Published by ilyalesik about 5 years ago

Package Rankings
Top 9.26% on Npmjs.org
Badges
Extracted from project README
Tests Status License NPM All Contributors
Related Projects