Giter Site home page Giter Site logo

axis's Introduction

CI CD Docs

Axis

Axis is a provider framework for the Roblox ecosystem.

Provider Example

Providers are simply tables with a name and a couple lifecycle methods.

local MyProvider = {}

function MyProvider:AxisPrepare()
	print("Prepare the provider")
end

function MyProvider:AxisStarted()
	print("Started")
end

return 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:

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:

local MyProvider = require(somewhere.MyProvider) -- Grab the other provider

local 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.
end

function 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:

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:

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.

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:

for _,module in ipairs(somewhere.MyProviderModules:GetChildren()) do
	local provider = require(module)
	provider.AxisName = module.Name -- Inject name
	Axis:AddProvider(provider)
end

axis's People

Contributors

sleitnick avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.