{"id":"jdevon/observable-value","name":"observable-value","scope":"jdevon","platform":"roblox","description":"A typed value you can read, set and observe.","version":"0.1.0","latest":"0.1.0","versions":["0.1.0"],"license":"MIT","licenseRating":"safe","licenseCaveats":[],"licenseVerified":true,"dependencies":{"lukadev-0/typed-promise":{"version":"^4.0.2","alias":"Promise"},"sleitnick/signal":{"version":"^2.0.1","alias":"Signal"}},"integrity":"f96e346ec774c32235913f2922c25d724b84f43e6bf581cc087b24bf84ec92e6","likes":0,"downloads":0,"install":"forest install jdevon/observable-value","url":"https://forest.dev/p/roblox/jdevon/observable-value","files":"https://api.forest.dev/ai/package/roblox/jdevon/observable-value/files","readme":"\n\n[observable-value/releases]: https://github.com/JDevon/observable-value/releases/latest\n[observable-value/wally]: https://wally.run/package/jdevon/observable-value\n\n\n\n[badges/github]: https://raw.githubusercontent.com/gist/cxmeel/0dbc95191f239b631c3874f4ccf114e2/raw/github.svg\n[badges/wally]: https://raw.githubusercontent.com/gist/cxmeel/0dbc95191f239b631c3874f4ccf114e2/raw/wally.svg\n\n# ObservableValue\n\nA typed value you can read, set, and observe. Adding a listener returns a cleanup function that's safe to call more than once.\n\nFull API reference at [jdevon.github.io/observable-value](https://jdevon.github.io/observable-value/).\n\n## Install\n\n[![badges/github]][observable-value/releases] [![badges/wally]][observable-value/wally]\n\nInstall with [Wally](https://wally.run) by adding it to your `wally.toml`:\n\n```toml\n[dependencies]\nObservableValue = \"jdevon/observable-value@0.1.0\"\n```\n\n## Usage\n\n```lua\nlocal ObservableValue = require(ReplicatedStorage.Packages.ObservableValue)\n\nlocal health = ObservableValue.new(100)\n\nlocal cleanup = health:onChanged(function(newHealth, oldHealth)\n\tprint(`health went from {oldHealth} to {newHealth}`)\nend)\n\nhealth:set(80) --> health went from 100 to 80\nhealth:update(function(current)\n\treturn current - 10\nend) --> health went from 80 to 70\n\ncleanup()\n\n-- yields until health drops to 0 or below, then continues with the final value\nlocal finalHealth = health:promiseValue(function(current)\n\treturn current <= 0, current\nend):expect()\nprint(`defeated at {finalHealth} health`)\n```\n\n## API\n\nEach member links to its full entry in the [API reference](https://jdevon.github.io/observable-value/api/ObservableValue).\n\n### Types\n\n- [`Disconnect`](https://jdevon.github.io/observable-value/api/ObservableValue#Disconnect) - the cleanup function returned by every listener method\n\n### Properties\n\n- [`version`](https://jdevon.github.io/observable-value/api/ObservableValue#version) - increases each time the value changes\n\n### Functions\n\n- [`.new`](https://jdevon.github.io/observable-value/api/ObservableValue#new) - creates an ObservableValue holding an initial value\n- [`:get`](https://jdevon.github.io/observable-value/api/ObservableValue#get) - returns the current value\n- [`:set`](https://jdevon.github.io/observable-value/api/ObservableValue#set) - sets the value\n- [`:update`](https://jdevon.github.io/observable-value/api/ObservableValue#update) - sets the value from the current one\n- [`:onChanged`](https://jdevon.github.io/observable-value/api/ObservableValue#onChanged) - calls back whenever the value changes\n- [`:onSet`](https://jdevon.github.io/observable-value/api/ObservableValue#onSet) - calls back on every `set`\n- [`:observe`](https://jdevon.github.io/observable-value/api/ObservableValue#observe) - calls back now with the current value, then on every change\n- [`:promiseValue`](https://jdevon.github.io/observable-value/api/ObservableValue#promiseValue) - resolves once the value passes a check\n- [`:Destroy`](https://jdevon.github.io/observable-value/api/ObservableValue#Destroy) - disconnects every listener (`:destroy` also works)\n","readmeTruncated":false}