{"id":"lucke0051/knit","name":"knit","scope":"lucke0051","platform":"roblox","description":"Knit is a lightweight game framework. This version is an experimental version with parallelization support. Original framework can be found at sleitnick/knit.","version":"1.1.1","latest":"1.1.1","versions":["1.0.0","1.0.1","1.1.0","1.1.1"],"license":"MIT","licenseRating":"safe","licenseCaveats":[],"licenseVerified":true,"dependencies":{"sleitnick/comm":{"version":"^0.3.0","alias":"Comm"},"evaera/promise":{"version":"^4.0.0","alias":"Promise"},"sleitnick/signal":{"version":"^1.5.0","alias":"Signal"}},"integrity":"84994426b61aebee3d857f67d3e2dbe3ce947bf4cd0dad256be34e696d851ff6","likes":0,"downloads":0,"install":"forest install lucke0051/knit","url":"https://forest.dev/p/roblox/lucke0051/knit","files":"https://api.forest.dev/ai/package/roblox/lucke0051/knit/files","readme":"Knit is a lightweight game framework. This version is an experimental version with parallelization support. The original framework can be found at [sleitnick/knit][knit].\r\n\r\n# Usage\r\nThis is is a fork of [sleitnick/knit][knit]. All the standard Knit documentation is avalible at [sleitnick.github.io/Knit][knitdocs]. Only APIs that do not exist in standard Knit is documented here.\r\n## Managers\r\nSimilarly to [services] and [controllers], this fork implements a new concept, managers. A manager is like a [service][services] or [controller][controllers], but they run on a separate actor.\r\n\r\nCurrent manager limitations:\r\n- No direct client <-> (nor ->) manager communication\r\n- Managers do not fully respect the ``KnitInit`` & ``KnitStart`` lifecycle\r\n\r\n### Lifecycle\r\n(Registration & creation are used interchangeably)\r\n\r\nManagers will not be registered before ``KnitInit``, but they may register before or after ``KnitStart``. A manager is ready to access [services] and [controllers] as soon as a manager is registered. You may ``GetManager``s in ``KnitStart``, but it is **not** safe to access manager methods in ``KnitStart``, nor ``KnitInit``.\r\n\r\n``KnitManagerCollection`` will not be parented to ``ServerScriptService`` (or ``ReplicatedStorage`` on clients) until it is ready, ``WaitForChild`` will yield until the module has been parented.\r\n\r\n### Example\r\n```lua\r\nlocal ServerScriptService = game:GetService(\"ServerScriptService\")\r\n\r\nlocal ManagerCollection = require(ServerScriptService:WaitForChild(\"KnitManagerCollection\"))\r\n\r\nlocal ExampleManager = ManagerCollection.CreateManager({\r\n\tName = \"ExampleManager\",\r\n})\r\n\r\nfunction ExampleManager:Compute(data)\r\n\ttask.desynchronize()\r\n\r\n\tlocal result\r\n\tfor key, value in data do\r\n\t\t--proccess\r\n\tend\r\n\r\n\treturn result\r\nend\r\n\r\nlocal ExampleService = ManagerCollection.GetService(\"ExampleService\")\r\nExampleService:Hello(\"world\")\r\n```\r\n\r\n### Parallelization & answers\r\nNote: whenever a function cannot be run in a desynchronized context, the ``ManagerCollection`` will automatically call ``task.synchronize()``. This is intentional. If you think this is an undesired behaviour, please open an issue.\r\n\r\nIf you ran the following code in a manager, the method would be called, but all return values would be discarded. The entirety of this code block can be run in a desynchronized context.\r\n```lua\r\nlocal ExampleService = ManagerCollection.GetService(\"ExampleService\")\r\nExampleService:Hello(\"world\")\r\n```\r\nIf you want to get the return values, you must access the method via the ``Answer`` subtable, this tells the ``ManagerCollection`` that you want the return values. It is important that you are aware that this will yield until due to the nature of ``BindableFunction``s that are used under the hood when calling via the ``Answer`` subtable.\r\n```lua\r\nlocal ExampleService = ManagerCollection.GetService(\"ExampleService\")\r\nlocal receivedData = ExampleService.Answer:Hello(\"world\")\r\n```\r\nMake sure you only use the ``Answer`` subtable when you really need to.\r\n\r\n\r\nIf you want to connect a method in a ``Manager`` directly in parallel, use the ``Parallel`` subtable. You cannot get return values from ``Parallel`` methods.\r\n```lua\r\nlocal Manager = ManagerCollection.GetManager(\"OtherManager\")\r\nManager.Parallel:Hello(\"world\")\r\n```\r\nNote that the ``Parallel`` subtable is only avalible on ``Manager``s.\r\n\r\n# API\r\n## ManagerCollection\r\nThe ``ManagerCollection`` should only be accessed from ``Manager``s.\r\n\r\nAccess the ``ManagerCollection`` on the server via:\r\n```lua\r\nlocal ServerScriptService = game:GetService(\"ServerScriptService\")\r\nlocal ManagerCollection = require(ServerScriptService:WaitForChild(\"KnitManagerCollection\"))\r\n```\r\nOn the client:\r\n```lua\r\nlocal ReplicatedStorage = game:GetService(\"ReplicatedStorage\")\r\nlocal ManagerCollection = require(ReplicatedStorage:WaitForChild(\"KnitManagerCollection\"))\r\n```\r\n\r\n### ManagerCollection.GetService(serviceName: string)\r\nExample:\r\n```lua\r\nlocal ExampleService = ManagerCollection.GetService(\"ExampleService\")\r\nlocal receivedData = ExampleService.Answer:Hello(\"world\")\r\n```\r\n### ManagerCollection.GetController(controllerName: string)\r\nOnly avalible on clients.\r\nExample:\r\n```lua\r\nlocal ExampleController = ManagerCollection.GetController(\"ExampleController\")\r\nlocal receivedData = ExampleController.Answer:Hello(\"world\")\r\n```\r\n### ManagerCollection.GetManager(managerName: string)\r\nUsed to access other ``Manager``s from a manager, does not travel through client <-> server.\r\nExample:\r\n```lua\r\nlocal OtherManager = ManagerCollection.GetManager(\"OtherManager\")\r\nOtherManager:Hello(\"world\")\r\n```\r\n### ManagerCollection.CreateManager(manager: Manager)\r\nRuns in a synchronized context.\r\n\r\nUsed to create/register a ``Manager``. Works similarly to [services] and [controllers].\r\nExample:\r\n```lua\r\nlocal ExampleManager = ManagerCollection.CreateManager({\r\n\tName = \"ExampleManager\",\r\n})\r\n```\r\n\r\n[knit]: https://github.com/Sleitnick/Knit\r\n[knitdocs]: https://sleitnick.github.io/Knit/\r\n[services]: https://sleitnick.github.io/Knit/docs/services\r\n[controllers]: https://sleitnick.github.io/Knit/docs/controllers","readmeTruncated":false}