Skip to content

About

No description, website, or topics provided.

Resources

Stars

0 stars

Watchers

0 watching

Forks

Latest commit

 

History

4 Commits

Folders and files

Repository files navigation

alien-signals-mapish

As if JavaScript Map() was abducted by alien-signals and had a baby.

When to use alien-signals-mapish

If you want to replace a small sub-set of Map() methods and add alien-signals' effect() on the Map()'s values.

Usage

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 chaining
  • effect() running when initialized is inherited behavior

Demo

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')) //42

Also bun test in CLI runs the .test.js file.

History

  • 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.

License

(c)2025 Tom Byrer MIT

About

No description, website, or topics provided.

Resources

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages