{"id":"astrealrblx/roactive","name":"roactive","scope":"astrealrblx","platform":"roblox","description":"Lightweight and fast reactive state library","version":"0.2.0","latest":"0.2.0","versions":["0.1.0","0.2.0"],"license":"MIT","licenseRating":"safe","licenseCaveats":["The package archive does not include its license text; the license is declared in its manifest metadata."],"licenseVerified":false,"dependencies":{},"integrity":"6a1c707c9f0a77a081780333aef919c3b748632ae8a0759d176a1253b8a876ee","likes":0,"downloads":0,"install":"forest install astrealrblx/roactive","url":"https://forest.dev/p/roblox/astrealrblx/roactive","files":"https://api.forest.dev/ai/package/roblox/astrealrblx/roactive/files","readme":"# Roactive\n\nWelcome to Roactive, a lightweight and fast reactive state library made specifically for use in Roblox. The creation of this library was inspired by Vue.js and Fusion.\n\nCode snippets show casing various Roactive features can be found in the [examples](/examples) directory.\n\n## Installation\n\nYou can install Roactive using [Wally](https://github.com/UpliftGames/wally) or by downloading the source and bringing it into your Rojo project.\n\n## Understanding Reactivity\n\nRoactive state is *reactive*. What this means is it can have dependents that actively listen for state changes. When a state occurs all dependents will be signaled to update accordingly.\n\n### State\n\nCreating Roactive state is really simple.\n\n```lua\nlocal myState = Roactive.State('Hello world!')\n```\n\nYou can also easily get and set the state's value.\n\n```lua\nprint(myState:Get()) --> Outputs: 'Hello world!'\nmyState:Set('World hello!')\nprint(myState:Get()) --> Outputs: 'World hello!'\n```\n\nIt's worth mentioning that Roactive state supports tuples.\n\n```lua\nlocal myState = Roactive.State(1, 2, 3)\n```\n\nOn its own state isn't very useful. State must be used as a dependency for it to have actual use. Roactive introduces various classes to help with this.\n\n### Watchers\n\nWatchers are inspired by Vue.js watchers and are extremely useful. A Watcher accepts a function called a target function. The target will capture all stateful dependencies within it and will recalled whenever those dependencies update.\n\n```lua\nRoactive.Watcher(function()\n  print(myState:Get())\nend)\n```\n\nNow `myState` is a dependency of this Watcher and this function will be called whenever `myState` changes.\n\n### Delay\n\nSometimes you want to hold a reference to your state that is delayed and doesn't instantly update. That's where delay comes in. It is both a dependent and dependency and essentially wraps a state object. It accepts a state object and a constant number that acts as the delay duration.\n\n```lua\nlocal myState = Roactive.State(true)\nlocal myStateDelayed = Roactive.Delay(myState, 3)\n```\n\nYou can update your state just like usual.\n\n```lua\nmyState:Set(false)\n\nprint(myState:Get()) --> Outputs: false\nprint(myStateDelayed:Get()) --> Outputs: true\n```\n\nThe delayed object outputs `true` because 3 seconds haven't yet passed and therefore its state hasn't updated to `false`.\n\n### Stopwatch\n\nStopwatches are sort of like a loop. They will repeatedly increment a position forever or until they reach a goal. They only have one argument, a settings table. They can be both a dependent and dependency.\n\n```lua\n{\n  interval: number?,        -- Position increments every x seconds (default 1)\n  increment: number?,       -- Increment amount (default 1)\n  startPosition: number?,   -- Start position (default 0)\n  goal: number?,            -- Goal position (default nil)\n  playing: any?,            -- Is playing (default true)\n}\n```\n\nThe `playing` settings accepts either a constant or a stateful object.\n\n```lua\nlocal isPlaying = Roactive.State(true)\nlocal stopwatch = Roactive.Stopwatch {\n  goal = 5,\n  playing = isPlaying\n}\n```\n\nIn order to listen to changes you can just use a Watcher.\n\n```lua\nRoactive.Watcher(function()\n  print(stopwatch:Get())\nend)\n```\n\nThe Watcher's target function will be called every time the Stopwatch updates just like any other object.","readmeTruncated":false}