{"id":"femphilic/state","name":"state","scope":"femphilic","platform":"roblox","description":"A simple state management library for Roblox","version":"1.1.3","latest":"1.1.3","versions":["1.0.1","1.1.0","1.1.1","1.1.2","1.1.3"],"license":"MIT","licenseRating":"safe","licenseCaveats":[],"licenseVerified":true,"dependencies":{},"integrity":"3e070cb06fe4c5bd01a2b50ee8eda3c80855971942d4e7cfea0ddae876ffec66","likes":0,"downloads":0,"install":"forest install femphilic/state","url":"https://forest.dev/p/roblox/femphilic/state","files":"https://api.forest.dev/ai/package/roblox/femphilic/state/files","readme":"# State Library\n\nA reactive state management library for Luau with type safety and performance optimizations.\n\n## Features\n\n- Type-safe reactive state\n- Automatic connection cleanup\n- Debug mode with detailed logging\n- Performance optimizations\n- Comprehensive error handling\n- Memory leak prevention\n\n## Installation\n\nYou can either copy the module directly into your Rojo codebase and require it like so:\n\n```luau\nlocal State = require(path.to.State)\n```\n\n..._or_ use Wally to install the library automatically:\n\n```toml\n# In wally.toml...\n# Other Wally properties\nstate = \"femphilic/state@1.1.2\" # Change the version as necessary and put this under dependencies\n# Other Wally properties\n```\n\n```sh\nwally install\n```\n\n```luau\nlocal State = require(game.ReplicatedStorage.Packages.state) -- Depends on where your \"packages\" are located in Studio, the name of your `Packages` folder, and the property name in the wally.toml file (e.g. with the example above it would be \"state\" like so)\n```\n\n## Basic Usage\n\n```luau\n-- Create a state\nlocal counter = State.new(0)\n\n-- Connect to changes\nlocal connection = counter:connect(function(value)\n  print(\"Counter changed to:\", value)\nend)\n\n-- Update state\ncounter:set(5)\n\n-- Disconnect when done with certain connection\nconnection:disconnect()\n\n-- Destroy state when done with state\nstate:destroy()\n```\n\n## Advanced Usage\n\n```luau\n-- Debug mode\nState.setDebugMode(true)\n\n-- Custom connection limits\nState.setMaxConnections(500)\n\n-- Named states for debugging\nlocal playerHealth = State.new(100, \"PlayerHealth\")\n```\n\n## API Reference\n\n### Static Functions\n\n- `State.new<T>(initialValue: T, debugName?: string): State<T>`\n  - Creates a new `state` object. If attempting to debug, `debugName` has to be set to a string\n- `State.setDebugMode(enabled: boolean): ()`\n  - Sets debug mode to `enabled` (default: `false`)\n- `State.getDebugMode(): boolean`\n  - Gets the current debug mode configuration (default: `false`)\n- `State.setMaxConnections(max: number): ()`\n  - Allows you to set the maximum number of connections each state can have. It is _highly_ recommended to keep this below `1000` (default: `100`)\n- `State.getMaxConnections(): number`\n  - Gets the current max connection configuration (default: `100`)\n\n### Class Functions\n\n_It is assumed that the self type is equal to `State<T>` in all situations_\n\n- `state:set(value: T): ()`\n  - Sets the state to `value`, firing all connected callbacks\n- `state:connect(callback: (value: T) -> ()): Connection`\n  - Connects `callback` to the state, firing whenever said state is set. Returns a connection (see `connection` below)\n- `state:destroy(): ()`\n  - Destroys the state, meaning that all connections are disconnected, the connection counter is set to `0`, and the state is rendered **unusable**.\n- `state:isDestroyed(): boolean`\n  - Returns the state's destroyed state\n- `state:setDebugName(name: string?): ()`\n  - Sets the state's debug name to `name`. This can also be set to `nil` if you would like to disable debugging for that state.\n- `state:getDebugName(): string?`\n  - Get the current state's debug name, which can potentially be `nil`.\n\n### Connection functions\n\nConnections are returned when calling `state:connect(callback)`.\n\n_It is assumed that the self type is equal to `Connection` in all situations_\n\n- `connection:disconnect(): ()`\n  - Disconnects the connection callback, meaning it'll no longer be called when `state:set(value)` is called\n- `connection:isConnected(): boolean`\n  - Returns whether the connection callback is connected to the state.\n","readmeTruncated":false}