Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/sleitnick/axis
A provider framework for the Roblox ecosystem
https://github.com/sleitnick/axis
Last synced: 2 months ago
JSON representation
A provider framework for the Roblox ecosystem
- Host: GitHub
- URL: https://github.com/sleitnick/axis
- Owner: Sleitnick
- License: mit
- Created: 2022-03-05T15:46:40.000Z (almost 3 years ago)
- Default Branch: main
- Last Pushed: 2022-03-07T21:00:27.000Z (almost 3 years ago)
- Last Synced: 2023-08-18T23:21:43.476Z (over 1 year ago)
- Language: Lua
- Homepage: https://sleitnick.github.io/Axis
- Size: 1.14 MB
- Stars: 10
- Watchers: 2
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- Changelog: CHANGELOG.md
- License: LICENSE.md
Awesome Lists containing this project
README
[![CI](https://github.com/Sleitnick/Axis/actions/workflows/ci.yaml/badge.svg)](https://github.com/Sleitnick/Axis/actions/workflows/ci.yaml)
[![CD](https://github.com/Sleitnick/Axis/actions/workflows/cd.yaml/badge.svg)](https://github.com/Sleitnick/Axis/actions/workflows/cd.yaml)
[![Docs](https://github.com/Sleitnick/Axis/actions/workflows/docs.yaml/badge.svg)](https://github.com/Sleitnick/Axis/actions/workflows/docs.yaml)# Axis
Axis is a provider framework for the Roblox ecosystem.
## Provider Example
Providers are simply tables with a name and a couple lifecycle methods.
```lua
local MyProvider = {}function MyProvider:AxisPrepare()
print("Prepare the provider")
endfunction MyProvider:AxisStarted()
print("Started")
endreturn MyProvider
```Providers must be explicitly added into Axis via `Axis:AddProvider()`. Once all providers are added, `Axis:Start()` will kick off the lifecycle methods of the providers.
A script to bootstrap Axis might look like this:
```lua
local Axis = require(somewhere.Axis)
local MyProvider = require(somewhere.MyProvider)Axis:AddProvider(MyProvider)
Axis:Start()
```## Using multiple providers
Because providers are just tables, it is easy for one provider to use another. Simply get a reference to the other provider (e.g. requiring its ModuleScript) and then access it after AxisStarted has fired. For example:
```lua
local MyProvider = require(somewhere.MyProvider) -- Grab the other providerlocal AnotherProvider = {}
function AnotherProvider:AxisPrepare()
-- Other providers are NOT safe to use here, because there's no guarantee
-- that they have all been prepared yet. Wait until AxisStarted.
endfunction AnotherProvider:AxisStarted()
-- Other providers are safe to use once the AxisStarted method fires.
MyProvider:DoSomething()
end
```## Extensions
Axis providers are very simple. In order to expand the possibilities of providers, extensions can be added. Extensions can be added at the Axis level (e.g. apply to all providers) or at the individual provider level.
Extensions allow code to run for a provider before certain lifecycle methods. This can be used to transform, inject, create networking, or do whatever is required to set up the providers for certain use-cases.
Below is an example of a simple logger extension:
```lua
local Axis = require(somewhere.Axis)Axis:AddExtension {
-- Assumes that a custom 'Name' field has been added to all providers:
BeforePrepare = function(provider)
print("Preparing provider", provider.Name)
end,
BeforeStarted = function(provider)
print("Starting provider", provider.Name)
end,
}
```Here is a similar example, but on a provider:
```lua
local MyProvider = {}MyProvider.AxisExtensions = {
{
BeforePrepare = function(provider)
print("BeforePrepare MyProvider")
end,
BeforeStarted = function(provider)
print("BeforeStarted MyProvider")
end,
},
}
```Extensions will run in the order of which they were added. Axis-level extensions run before provider-level extensions.
## Memory categories
Because Axis providers are started from one source, the default memory label within the Developer Console will appear the same for all providers. To solve this, Axis will automatically assign a memory category if the `AxisName` field is set.
```lua
local MyProvider = {}MyProvider.AxisName = "MyProvider"
```When MyProvider is prepared/started, any memory usage will show up within the MyProvider label in the Developer Console memory section.
If the script being used to bootstrap Axis is grabbing each provider from its own ModuleScript, then a simple way to inject this is to set the `AxisName` property to the ModuleScript's name. For example:
```lua
for _,module in ipairs(somewhere.MyProviderModules:GetChildren()) do
local provider = require(module)
provider.AxisName = module.Name -- Inject name
Axis:AddProvider(provider)
end
```