Gathering detailed insights and metrics for rmemo
Gathering detailed insights and metrics for rmemo
Gathering detailed insights and metrics for rmemo
Gathering detailed insights and metrics for rmemo
@ctx-core/rmemo-svelte
rmemo & svelte store interop
relysjs
Reactive Web app server focusing on MPAs with a simple server route & browser build api...uses Bunjs, Elysia, ESBuild, rmemo, & ctx-core
rebuildjs
Reactive esbuild...simple hackable alternative to vite for Multi Page Apps
@rebuildjs/tailwindcss
Tailwindcss integration with rebuildjs
npm install rmemo
Typescript
Module System
Node Version
NPM Version
JavaScript (100%)
Total Downloads
0
Last Day
0
Last Week
0
Last Month
0
Last Year
0
Apache-2.0 License
6 Stars
275 Commits
1 Watchers
1 Branches
1 Contributors
Updated on Sep 01, 2024
Latest Version
0.51.32
Package Id
rmemo@0.51.32
Unpacked Size
64.00 kB
Size
15.12 kB
File Count
7
NPM Version
10.8.1
Node Version
22.4.1
Published on
Sep 01, 2024
Cumulative downloads
Total Downloads
Last Day
0%
NaN
Compared to previous day
Last Week
0%
NaN
Compared to previous week
Last Month
0%
NaN
Compared to previous month
Last Year
0%
NaN
Compared to previous year
1
7
rmemo is a tiny no-fluff reactive state management library. The primitive is a reactive memo. A reactive signal is a reactive memo that has a public .set
function. rmemo includes memosig
, lock_memosig
, & a rich api for your reactive state management needs. Features include:
memo_
signal_
memosig_
lock_memosig_
ctx-core/be
imports | size |
---|---|
memo_ | 358 B |
memo_ + sig_ | 381 B |
memo_ + sig_ + be_ + ctx_ | 476 B |
memo_ + sig_ + be_ + ctx_ + be_memo_pair_ + be_sig_triple_ | 559 B |
1npm i ctx-core 2# or 3npm i rmemo
rmemo is part of the ctx-core package. Importing ctx-core/rmemo
will enable usage of rmemo. There is also a standalone rmemo
package.
1// users.ts 2import { sig_ } from 'rmemo' // or 'ctx-core/rmemo' 3export const user_a$ = sig_<User[]>([], [ 4 user_a$=> 5 fetch('https://my.api/users') 6 .then(res=>res.json()) 7 .then(user_a=>user_a$.set(user_a)) 8 // Make sure async errors are handled 9 .catch(err=>console.error(err)) 10]) 11export function user__add(user:User) { 12 user_a$.set([...user_a$(), user]) 13} 14export interface User { 15 id:number 16 name:string 17}
1// admins.ts 2import { memo_ } from 'rmemo' // or 'ctx-core/rmemo' 3import { user_a$ } from './users.js' 4export const admin_a$ = memo_(()=>user_a$().filter(i=>i.isAdmin))
rmemo provides optional opt-in reactivity to relementjs. Gives reativity to Element rendering, Element attributes/props rendering.
rmemo is a small & focused library. memo_
is like nanostore's computed
, svelte's derived
, solidjs' createMemo
, & VanJS' derive
. & sig_
is like nanostore's atom
, svelte's writable
, solidjs' createSignal
, & VanJS' state
.
rmemo | nanostores | solidjs | sveltejs | vanjs | |
---|---|---|---|---|---|
small payload | ✅ | ✅ | ✅ | ✅ | ✅ |
performant | ✅ | ✅ | ✅ | ✅ | ✅ |
autosubscriptions | ✅ | ❌ | ✅ | ❌ | ✅ |
server side reactivity | ✅ | ✅ | ✅ | ✅ | ❌ |
diamond dependencies | ✅ | ✅ | ✅ | ✅ | ❌ |
independent from component tree | ✅ | ✅ | ❌ (next version) | ✅ | ✅ |
reactive async | ✅ | ❌ (next version) | ✅ | ✅ | ❌ |
terse api | ✅ | ❌ | ❌ | ❌ | ✅ |
contexts | ✅ | ❌ (next version) | ✅ (component tree) | ✅ (component tree) | ❌ |
Automatic Garbage Collection of derived reactives | ✅ | ❌ | ✅ | ❌ | ✅ |
ctx-core is a general purpose context library. ctx-core's context functions (be_
& ctx__new
) are compatible with any state management library. rmemo exports the ctx-core/be
package.
function | description |
---|---|
memosig_ | A memo signal & a settable memo. Changes to the parent memo resets the memosig, even after setting the memosig._ prop. |
lock_memosig_ | A memo signal & a settable memo. Changes to the parent memo only resets the memosig when if the lock_memosig._ setter was not set. If the lock_memosig._ setter was set, then changes to the parent memo do not reset the lock_memosig . |
be_sig_triple_ | Returns an array of 3 context be_ functions. sig object getter, value getter, & value setter |
id_be_sig_triple_ | Same as be_sig_triple_ + sets the id of the be function |
ns_id_be_sig_triple_ | Same as be_sig_triple_ + sets the id of the be function & operates on the given ctx namespace. |
ns_be_sig_triple_ | Same as be_sig_triple_ & operates on the given ctx namespace. |
be_memo_pair_ | Returns an array of 2 context be_ functions. memo object getter & value getter. |
id_be_memo_pair_ | Same as be_memo_pair_ + sets the id of the be function |
ns_id_be_memo_pair_ | Same as be_memo_pair_ + sets the id of the be function & operates on the given ctx namespace. |
ns_be_memo_pair_ | Same as be_memo_pair_ & operates on the given ctx namespace. |
be_memosig_triple_ | Returns an array of 3 context be_ functions. memosig object getter, value getter, & value setter |
id_be_memosig_triple_ | Same as be_memosig_triple_ + sets the id of the be function |
ns_id_be_memosig_triple_ | Same as be_memosig_triple_ + sets the id of the be function & operates on the given ctx namespace. |
ns_be_memosig_triple_ | Same as be_memosig_triple_ & operates on the given ctx namespace. |
be_lock_memosig_triple_ | Returns an array of 3 context be_ functions. lock_memosig object getter, value getter, & value setter |
id_be_lock_memosig_triple_ | Same as be_lock_memosig_triple_ + sets the id of the be function |
ns_id_be_lock_memosig_triple_ | Same as be_lock_memosig_triple_ . Also sets the id of the be function & operates on the given ctx namespace. |
ns_be_lock_memosig_triple_ | Same as be_lock_memosig_triple_ & operates on the given ctx namespace. |
rmemo__wait | Wait for memo to match given condition with a timeout |
rmemo__off | Turn off a memo & remove references to parent memos. Note that the parent memo references the child rmemo using WeakRef . This allows the child memo to not receive updates pending Garbage Collection. |
rmemo__on | Turn on a memo. Re-adds the memo to the WeakRef held by parent memos. |
rmemo__unset | Unset the memo value. Calling the memo again causes the memo to refresh. |
ctx
)Contexts are useful for managing state & disposing of state with Garbage Collection. The context holds state. Garbage Collection disposes the state by removing all active references to the ctx
.
rmemo includes functions to support contexts using ctx-core. ctx-core uses dependency injection. By passing the ctx
as an argument to a function. Most front-end libraries support Context
components. These libraries include React, Sveltejs, Solidjs, & others. Assigning the ctx
to the Context
component give child components access to the ctx
.
This example works on the browser side. There is only one instance user_a$
& admin_a$
to render the UI. The server handles concurrent requests. Concurrent requests disallows global or module variables to store request state. So memos stored as module variables is not concurrency safe.
A ctx
solves this issue by storing the memo instances in the ctx
. Each request instantiates a ctx
via ctx_()
. A shorted alias to ctx__new()
.
ctx-core uses the be_
function to define a memoized function to set a "slot" in the ctx
.
1// users.ts 2import { be_, type ctx_T, sig_ } from 'rmemo' 3export const user_a$_ = be_(()=> 4 sig_<User[]>([], [ 5 user_a$=> 6 fetch('https://an.api/users') 7 .then(res=>res.json()) 8 .then(user_a=>user_a$.set(user_a)) 9 .catch(err=>console.error(err)) 10 ])) 11export function user__add(ctx:ctx_T, user:User) { 12 user_a$_(ctx).set([...user_a$_(ctx)(), user]) 13} 14export interface User { 15 id:number 16 name:string 17}
1// admins.ts 2import { be_, memo_ } from 'rmemo' 3import { user_a$_ } from './users.js' 4export const admin_a$_ = be_(ctx=> 5 memo_(()=> 6 user_a$_(ctx)() 7 .filter(i=>i.isAdmin)))
Calling user_a$_(ctx)()
& admin_a$_(ctx)()
is awkward. So rmemo provides some helper functions.
1// users.ts 2import { be_sig_triple_, type ctx_T } from 'rmemo' 3export const [ 4 user_a$_, 5 user_a_, 6 user_a__set, 7] = be_sig_triple_<User[]>( 8 ()=>[], [ 9 (ctx, user_a$)=> 10 fetch('https://an.api/users') 11 .then(res=>res.json()) 12 .then(user_a=>user_a$.set(user_a)) 13 .catch(err=>console.error(err)) 14 ]) 15export function user__add(ctx:ctx_T, user:User) { 16 user_a__set(ctx, [...user_a_(ctx), user]) 17} 18export interface User { 19 id:number 20 name:string 21}
1// admins.ts 2import { be_memo_pair_ } from 'rmemo' 3import { type User, user_a_ } from './users.js' 4export const [ 5 admin_a$_, 6 admin_a_, 7] = be_memo_pair_(ctx=> 8 user_a_(ctx) 9 .filter(i=>i.isAdmin))
You may have noticed the usage of underscore casing. And the trailing _
for factory functions. The Tag Vector name system describes these patterns.
I liked & used some popular reactive state management solutions. These popular libraries include nanostores, solidjs, svelte, & vanJS. I needed a general solution that I can use on the browser & server, with web UIs & domain libraries. For automating builds & deployments. These projects focus on their particular objectives. I found they were unable to support my use cases in one way or another.
An impasse in adding autosubscriptions to nanostores. An impasse in adding server-side reactive support to vanJS. Both led me to create rmemo.
I use the tag vector name system. An app can have many reactive elements defined. Especially when these reactive elements make up the domain model. Tag Vector provides terse & expressive api for these many instances.
No vulnerabilities found.
No security vulnerabilities found.