As if JavaScript Map() was abducted by alien-signals and had a baby.
If you want to replace a small sub-set of Map() methods and add alien-signals' effect() on the Map()'s values.
package.json if using with Node/Bun/etc
"dependencies": {
"alien-signals-mapish": "github:tomByrer/alien-signals-mapish",
...Notes:
- the map key has a type of 'any' to emulate what
Map()allows, but suggested to use only strings, since that is all that been actually tested set()doesn't return anything, so no chainingeffect()running when initialized is inherited behavior
import SignalMapish from 'alien-signals-mapish'
const presets = [['count', 0], ['name', 'Tom']]
const mapish = new SignalMapish(presets)
// effect runs when initialized and only when count changes
mapish.effect(()=>{
console.info('count is now', mapish.get('count'))
}) // count is now 0
console.log(mapish.has('count') ) // true
console.log(mapish.get('count') ) // 0
console.log(mapish.has('missing') ) // false
console.log(mapish.get('missing') ) // undefined
// fails mapish.set('count', 42).set('newkey', 'fails')
mapish.set('count', 42) // no return, but effect should print: count is now 42
mapish.set('name', 'Thomas') // should not trigger effect
console.log(mapish.get('count')) //42Also bun test in CLI runs the .test.js file.
- 0.1.0 init, Developed for my
state-shifterFinite State Machine as a progressive enhancement to JS'sMap(). Uses alien-signals@3.1.2
- 1.0.20260225
- merged in alien-signals-getset wrapper
- improved get()/set() performance
-
- getSnapshot() : returns an object of the current array of key,value arrays
-
- mergePresets() : add new key,value arrays IF the key does not currently exist
-
- queueUpdates()/resumeUpdates() : helpers that will stop Signal updates until resumed if you want to batch changes.
(c)2025 Tom Byrer MIT