Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Pingid/lickle-state

Repository files navigation

Lickle State

A lightweight reactive pub/sub utility for Map, Set, and plain objects.

Build Status Build Size Version

Installation

npm install @lickle/state
# or
yarn add @lickle/state
# or
pnpm add @lickle/state

Usage

Reactive Objects

Wrap any object, Map, or Set to make them reactive:

import { reactiveRecord, reactiveMap, reactiveSet, subscribe } from '@lickle/state'

// Reactive object
const state = reactiveRecord({ count: 0 })
subscribe(state, 'count', () => console.log(`Count: ${state.count}`))
state.count += 1 // Logs: Count: 1

// Reactive map
const map = reactiveMap(new Map())
subscribe(map, 'key', () => console.log('Key changed!'))
map.set('key', 'value') // Logs: Key changed!

// Reactive set
const set = reactiveSet(new Set())
subscribe(set, () => console.log('Set updated!'))
set.add('item') // Logs: Set updated!

Batch Updates

Group multiple updates to trigger a single notification:

import { batch } from '@lickle/state'

batch(state, () => {
  state.count += 1
  state.count += 1
}) // Logs: Count: 2 (once)

Suspend Listeners

Pause notifications while making updates:

import { suspend } from '@lickle/state'

suspend(state, () => {
  state.count += 1
}) // No logs

License

MIT © Dan Beaven

About

Library of reactive state primities

Resources

Stars

Watchers

Forks

Packages

No packages published