Skip to content

Conversation

@littensy
Copy link
Owner

@littensy littensy commented May 4, 2025

Rewrite Charm using the alien-signals reactive algorithm.

Why?

Adopting alien-signals brings benefits and guarantees like predictable effect ordering, nested effect cleanup, and more efficient computed() memoization, all without a significant compromise to performance. Building Charm on this signal algorithm should improve Charm's overall efficiency and reliability.

What's New?

  • Added effectScope(fn) to clean up a group of effects and subscriptions
  • Added onCleanup(fn) to run fn once the current effect/scope reruns or gets disposed
  • Added listen(selector, listener) for immediate subscriptions
  • Optimized mapped() to cache values and prevent unnecessary updates
  • Optimized computed() to use lazy evaluation instead of eager updates

Breaking Changes

  • Nested effects automatically dispose when the parent effect reruns or the scope is disposed
    • This applies to subscribe, listen, and observe.
    • Create a "detached" effect scope if you need to run code outside the parent effect's lifecycle.
  • Effects created inside the observer function now automatically dispose when the item is removed
  • Renamed batch() to batched()
  • Renamed peek() to untracked()

Notes

  • Effects created in peek() still clean up with the parent effect/scope. Use a detached effectScope to run code that's detached from the parent effect.
  • In Roblox Studio, the following flags will be enabled by default:
    • strict: Formerly _G.__DEV__, this bans unsafe yielding and enables additional checks in Charm Sync.
    • frozen: Deep-freeze all atom values to enforce immutable state updates.

@littensy littensy added the enhancement New feature or request label May 4, 2025
@littensy littensy marked this pull request as draft May 5, 2025 08:33
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

enhancement New feature or request

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Create useAtomBinding function Add option to subscribe to run callback immediately

2 participants