{"id":"quenty/binder","name":"binder","scope":"quenty","platform":"roblox","description":"Utility object to Bind a class to Roblox object, and associated helper methods.","version":"4.2.1-canary.140ed9d6.7","latest":"4.2.1-canary.140ed9d6.7","versions":["4.2.1-canary.140ed9d6.1","4.2.1-canary.140ed9d6.2","4.2.1-canary.140ed9d6.4","4.2.1-canary.140ed9d6.5","4.2.1-canary.140ed9d6.6","4.2.1-canary.140ed9d6.7"],"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":{"quenty/maid":{"version":"^2.0.1-canary","alias":"Maid"},"quenty/promise":{"version":"^3.1.3-canary","alias":"Promise"},"quenty/signal":{"version":"^2.0.0-canary","alias":"Signal"},"quenty/loader":{"version":"^3.1.1-canary","alias":"loader"}},"integrity":"2b2baebf7f39a66d929b9fb175d865d6f20f960ff40193eb49a53acbf3e058c6","likes":0,"downloads":0,"install":"forest install quenty/binder","url":"https://forest.dev/p/roblox/quenty/binder","files":"https://api.forest.dev/ai/package/roblox/quenty/binder/files","readme":"## Binder\r\n<div align=\"center\">\r\n  <a href=\"http://quenty.github.io/api/\">\r\n    <img src=\"https://img.shields.io/badge/docs-website-green.svg\" alt=\"Documentation\" />\r\n  </a>\r\n  <a href=\"https://discord.gg/mhtGUS8\">\r\n    <img src=\"https://img.shields.io/badge/discord-nevermore-blue.svg\" alt=\"Discord\" />\r\n  </a>\r\n  <a href=\"https://github.com/Quenty/NevermoreEngine/actions\">\r\n    <img src=\"https://github.com/Quenty/NevermoreEngine/actions/workflows/build.yml/badge.svg\" alt=\"Build and release status\" />\r\n  </a>\r\n</div>\r\n\r\nBinders bind a class to Roblox Instance\r\n\r\n## Installation\r\n```\r\nnpm install @quenty/binder --save\r\n```\r\n\r\n## Usage\r\n\r\n```lua\r\n-- Setup a class!\r\nlocal MyClass = {}\r\nMyClass.__index = MyClass\r\n\r\nfunction MyClass.new(robloxInstance)\r\n\tprint(\"New tagged instance of \", robloxInstance)\r\n\treturn setmetatable({}, MyClass)\r\nend\r\n\r\nfunction MyClass:Destroy()\r\n\tprint(\"Cleaning up\")\r\n\tsetmetatable(self, nil)\r\nend\r\n\r\n-- bind to every instance with tag of \"TagName\"!\r\nlocal binder = Binder.new(\"TagName\", MyClass)\r\nbinder:Start() -- listens for new instances and connects events\r\n```\r\n\r\n## API\r\n\r\n### `Binder.new(tagName, constructor)`\r\nCreates a new binder object.\r\n\r\n### `Binder.isBinder(value)`\r\nRetrieves whether or not its a binder\r\n\r\n### `Binder:Start()`\r\nListens for new instances and connects to the GetInstanceAddedSignal() and removed signal!\r\n\r\n### `Binder:GetTag()`\r\nReturns the tag name that the binder has\r\n\r\n### `Binder:GetConstructor()`\r\nReturns whatever was set for the construtor. Used for meta-analysis of the binder, such as extracting new\r\n\r\n### `Binder:ObserveInstance(inst, callback)`\r\nFired when added, and then after removal, but before destroy!\r\n\r\n### `Binder:GetClassAddedSignal()`\r\nReturns a new signal that will fire whenever a class is bound to the binder\r\n\r\n### `Binder:GetClassRemovingSignal()`\r\nReturns a new signal that will fire whenever a class is removed from the binder\r\n\r\n### `Binder:GetAll()`\r\nReturns all of the classes in a new table\r\n\r\n```lua\r\nlocal birdBinder = Binder.new(\"Bird\", require(\"Bird\")) -- Load bird into binder\r\n\r\n-- Update every bird every frame\r\nRunService.Stepped:Connect(function()\r\n\tfor _, bird in pairs(birdBinder:GetAll()) do\r\n\t\tbird:Update()\r\n\tend\r\nend)\r\n\r\n```\r\n### `Binder:GetAllSet()`\r\nFaster method to get all items in a binder\r\n\r\nNOTE: Do not mutate this set directly\r\n\r\n```lua\r\nlocal birdBinder = Binder.new(\"Bird\", require(\"Bird\")) -- Load bird into binder\r\n\r\n-- Update every bird every frame\r\nRunService.Stepped:Connect(function()\r\n\tfor bird, _ in pairs(birdBinder:GetAllSet()) do\r\n\t\tbird:Update()\r\n\tend\r\nend)\r\n\r\nbirdBinder:Start()\r\n```\r\n\r\n### `Binder:Bind(inst)`\r\nBinds an instance to this binder using collection service and attempts to return it if it's bound properly. See BinderUtils.promiseBoundClass() for a safe way to retrieve it.\r\n\r\nNOTE: Do not assume that a bound object will be retrieved\r\n\r\n### `Binder:Unbind(inst)`\r\nUnbinds the instance by removing the tag\r\n\r\n### `Binder:BindClient(inst)`\r\nSee :Bind(). Acknowledges the risk of doing this on the client. Using this acknowledges that we're intentionally binding on a safe client object, i.e. one without replication. If another tag is changed on this instance, this tag will be lost/changed.\r\n\r\n### `Binder:UnbindClient(inst)`\r\nSee Unbind(), acknowledges risk of doing this on the client.\r\n\r\n### `Binder:Get(inst)`\r\nReturns a version of the clas\r\n\r\n### `Binder:Promise(inst, cancelToken)`\r\n\r\n### `Binder:Destroy()`\r\nCleans up all bound classes, and disconnects all events\r\n","readmeTruncated":false}