[(https://create.roblox.com/store/asset/82543936787682/LuaObservable)]
(Idk why its not in image. Cringe)
What & Why
LuauObservable is an implementation of the Observable pattern in pure Luau. In short, it’s an add—on over regular Signals that makes the code cleaner, clearer, and easier to maintain.
Let’s visualize it:
Signals:
RBXScriptSignal:Connect(function(arg)
if debaunce then return end
handleDebaunceLogic()
handleValidityOfArg(arg)
local health = getHealth(arg)
Callback(health)
end)
Observable:
--chaining | mutable (every :operator() creates new object)
LuaObservable.fromSignal(RBXScriptSignal)
:debaunce(n)
:filter(handleValidityOfArg)
:map(getHealth)
:subscribe { next = callback }
--pipe |immutable (one object for all time)
local source = LuaObservable.fromSignal(RBXScriptSignal)
local result = LuaObservable.fromSignal(RBXScriptSignal):pipe(
Operators.debounce(n),
Operators.filter(handleValidityOfArg),
Operators.map(getHealth)
):subscribe { next = callback }
Adventages
- Readability through decomposition
All checks are moved to the top by the .filter(). chain. The main logic remains clean and focused on its task. - Data composition and transformation
- now I will not add here more, but soon…
How to use
🔧 API Reference
Constructors:
· Constructors.fromSignal(signal) - Create from Roblox signals
· Constructors.fromArray(array) - Create from array values
· Constructors.of(...) - Create from multiple arguments
Operators:
· .map(fn) - Transform values
· .filter(fn) - Filter based on condition
· .take(n) - Take first n values
· .tap(fn) - Execute side effect
· .debounce(seconds) - Debounce events (soon)
· .throttle(seconds) - Throttle events (soon)
Practical Applications
Game Mechanics:
· Ability cooldown systems
· Combo systems with timing
· Damage calculation pipelines
· Quest progression tracking
UI Systems:
· Button state management
· Form validation chains
· Animation sequencing
· Tooltip display logic
Data Processing:
· Player stat calculations
· Inventory filtering/sorting
· Leaderboard updates
· Analytics event processing
(I mean, all that implements with signals can be implement with observable)
Architecture & Design
(Work without type errors on new typechecker)
·
Strict Luau Types - Full type safety and IDE autocomplete (maybe wont work with signal constructor. You still can make local variable: LuaObservable.Observable<value> = …
·
normal weight - Minimal overhead with immutable pipe; big overhead with mutable variant (That’s why you should think about how exactly to implement this and avoid creating new observables whenever possible.)
·
Dual API - Both mutable chaining and immutable pipe styles
·
Seamless Integration - Works with any Roblox signal. I would even say that it works with anything if you think about how your data interacts with the observable
Community & Contribution
LuauObservable is actively maintained and welcomes community involvement:
·
Report bugs - Found an issue? Let us know!
·
Suggest features - What operators do you need?
·
Have improvements? Id like to see them!
The declarative nature makes code easier to reason about, especially when returning to it months later or when handing off to other developers.
Documentation: [Soon!]
Also will be useful:
Pseudo-OOP in luau: Click here
Deterministic and non-deterministic state machines: Click here
ECS in luau and how to cook it: Click here
