Gathering detailed insights and metrics for nanostores-persistent-solid
Gathering detailed insights and metrics for nanostores-persistent-solid
Gathering detailed insights and metrics for nanostores-persistent-solid
Gathering detailed insights and metrics for nanostores-persistent-solid
Drop-in replacement for Nano Stores Persistent and Nano Stores Solid that adds support for persistent atoms/maps in Solid SSR environments.
npm install nanostores-persistent-solid
Typescript
Module System
Node Version
NPM Version
71.8
Supply Chain
98.4
Quality
75.5
Maintenance
100
Vulnerability
100
License
TypeScript (84.06%)
JavaScript (15.94%)
Total Downloads
629
Last Day
1
Last Week
1
Last Month
5
Last Year
197
MIT License
4 Stars
35 Commits
1 Forks
1 Watchers
1 Branches
1 Contributors
Updated on Sep 08, 2024
Minified
Minified + Gzipped
Latest Version
0.1.7
Package Id
nanostores-persistent-solid@0.1.7
Unpacked Size
28.19 kB
Size
7.27 kB
File Count
10
NPM Version
8.18.0
Node Version
18.8.0
Cumulative downloads
Total Downloads
Last Day
0%
1
Compared to previous day
Last Week
0%
1
Compared to previous week
Last Month
-82.1%
5
Compared to previous month
Last Year
-1.5%
197
Compared to previous year
1
2
Drop-in replacement for both Nano Stores Persistent and Nano Stores Solid that adds/fixes support for persistent atoms and maps in Solid SSR environments.
The original version of Nano Stores Solid does not support Nano Stores Persistent in SSR environments due to an issue in which pre-rendered content does not re-render to show updated content from persistent storage engines. This is demonstrated in this minimal reproduction:
This library modifies contents from both Nano Stores Solid and Nano Stores Persistent in order to rectify the issue. Since code from the framework-agnostic Nano Stores Persistent library had to be modified just for it to work in a highly-specific Solid SSR environment, a PR was not opened to upstream these changes. However, if and when the original libraries are updated to fix this issue in a manner which is satisfactory to the original authors, this library will be archived.
Install it:
1pnpm add nanostores nanostores-persistent-solid # or npm or yarn
Use it:
1// store.ts 2import { persistentAtom, persistentMap } from 'nanostores-persistent-solid'; 3 4export const testAtom = persistentAtom('testKey', 'testValue'); 5 6export const testMap = persistentMap( 7 'testPrefix:', 8 { 9 valueOne: 1, 10 valueTwo: 2 11 }, 12 { 13 encode: JSON.stringify, 14 decode: JSON.parse 15 } 16);
1// Component.tsx 2import { useStore } from 'nanostores-persistent-solid'; 3import { testAtom, testMap } from './store'; 4 5function Component() { 6 const $testAtom = useStore(testAtom); 7 const $testMap = useStore(testMap); 8 9 return ( 10 <> 11 <div>{$testAtom()}</div> 12 <div>{$testMap().valueOne}</div> 13 <div>{$testMap().valueTwo}</div> 14 </> 15 ); 16}
The use of computed
from Nano Stores differs from regular usage in one small aspect — the parent atoms/maps for which the computed atom is based off have to be passed into useStore
at least once within the application. Therefore, it is recommended to simply pass any parent atoms/maps into useStore
right before passing the computed atom into useStore
wherever the computed atoms are used in the application:
1// Component.tsx 2import { useStore } from 'nanostores-persistent-solid'; 3import { parentAtom, computedAtom } from './store'; 4 5function Component() { 6 useStore(parentAtom); // assigning variable to return value is not required if not used 7 const computedAtom = useStore(computedAtom); 8 9 return <div>{computedAtom()}</div>; 10}
Code from the original libraries were modified in such a way that:
Therefore, this also means that full documentation about the API of this library and how it can be used are readily found in the original repositories at Nano Stores Persistent and Nano Stores Solid.
The test suite was rewritten to ensure that the modified Solid integration is still able to handle the use-case of default atoms and maps which Nano Stores Solid could originally handle, and also the newly-added use-case of persistent atoms and maps.
Do note that areas of the API from the original libraries which were not touched by the rewrites (specifically API concerning storage engines, encoders and test storage engines from Nano Stores Persistent) are not included in the tests.
This library is an ESM-only package, so as to adhere to the output format conventions set by Nano Stores libraries. This means that you will need to use ES modules in your application in order to import this library.
MIT
No vulnerabilities found.
No security vulnerabilities found.