|
1 | | -# rmemo |
2 | | -Tiny Reactive Memo + Signal library (377B) |
| 1 | +# rmemo (Reactive Memo) |
| 2 | +rmemo is a tiny (377B) no-fluff state management library using reactive memos & reactive signals for the server & |
| 3 | +browser. This includes: |
| 4 | + |
| 5 | +* reactive memos |
| 6 | +* reactive signals |
| 7 | +* autosubscriptions |
| 8 | +* async support |
| 9 | +* a terse & focused api |
| 10 | +* performance |
| 11 | +* integration with garbage collector |
| 12 | + |
| 13 | +## usage |
| 14 | + |
| 15 | +```ts |
| 16 | +import { rmemo_, rsig_ } from 'rmemo' |
| 17 | + |
| 18 | +export const user_a$ = rsig_<User[]>([], async user_a$ => { |
| 19 | + user_a$(await fetch('https://an.api/users').then(res => res.json())) |
| 20 | +}) |
| 21 | + |
| 22 | +export function user__add(user: User) { |
| 23 | + user_a$([...user_a$(), user]) |
| 24 | + // also supports ._ getters & setters |
| 25 | + // user_a$._ = [...user_a$._, user] |
| 26 | +} |
| 27 | +``` |
| 28 | +```ts |
| 29 | +// store/admins.ts |
| 30 | +import { rmemo_ } from 'rmemo' |
| 31 | +import { user_a$ } from './users.js' |
| 32 | + |
| 33 | +export const admin_a$ = rmemo_(() => user_a$().filter(i => i.isAdmin)) |
| 34 | +``` |
| 35 | + |
| 36 | +*Integrations with front-end frameworks pending...* |
| 37 | + |
| 38 | +## motivation |
| 39 | + |
| 40 | +I'm a fan of reactive state management solutions provided by nanostores, solidjs, svelte, & vanJS. I wanted one of |
| 41 | +these solutions to be a general solution that I can use on the browser & server, with web UIs & domain libraries. |
| 42 | +Each of these projects are focused on their particular objectives. I found they were unable to support my use cases |
| 43 | +in one way or another. |
| 44 | + |
| 45 | +Between an impasse in adding autosubscriptions to nanostores & adding server-side reactive support to vanJS, I |
| 46 | +created rmemo. |
| 47 | + |
| 48 | +## how is rmemo different? |
| 49 | + |
| 50 | +rmemo is a small & focused library. It supports `rmemo_` (like nanostores `computed`, svelte `derived`, |
| 51 | +solidjs `createMemo`, & VanJS `derive`) & `rsig_` (like nanostore `atom`, svelte `writable`, solidjs |
| 52 | +`createSignal`, & VanJS `state`). |
| 53 | + |
| 54 | +| **** | **rmemo** | **nanostores** | **solidjs** | **sveltejs** | **vanjs** | |
| 55 | +|-------------------------------------|-----------|------------------|------------------|--------------|-----------| |
| 56 | +| **small payload** | ✅ | ✅ | ✅ | ✅ | ✅ | |
| 57 | +| **performant** | ✅ | ✅ | ✅ | ✅ | ✅ | |
| 58 | +| **autosubscriptions** | ✅ | ❌ | ✅ | ❌ | ✅ | |
| 59 | +| **server side reactivity** | ✅ | ✅ | ✅ | ✅ | ❌ | |
| 60 | +| **diamond dependencies** | ✅ | ✅ | ✅ | ✅ | ❌ | |
| 61 | +| **independent from component tree** | ✅ | ✅ | ❌ (next version) | ✅ | ✅ | |
| 62 | +| **reactive async** | ✅ | ❌ (next version) | ✅ | ❌ | ❌ | |
| 63 | +| **terse api** | ✅ | ❌ | ❌ | ❌ | ✅ | |
| 64 | +| **ecosystem of libraries** | ❌ | ✅ | ✅ | ✅ | ✅ | |
| 65 | + |
| 66 | +It will not support contexts. A general purpose context library, such as ctx-core fulfills that need in a more |
| 67 | +effective manner. Note that ctx-core can be used with any of these libraries. |
0 commit comments