Skip to main content

Sapling

The main / core package of the Sapling framework.

Properties

Dispatchers

This item is read only and cannot be modified. Read Only
Sapling.Dispatchers: any

All the built-in dispatchers lifecycle dispatchers.

Functions

loadServices

Sapling.loadServices(
parentInstance,
recursiveboolean?
) → ()

Loads all module scripts under parent ignoring anything which isn't a ModuleScript instance.

loadPackages

Sapling.loadPackages(packagesFolderFolder) → ()

This function only needs to be called if you are using any other Sapling Framework packages, simply point it to your Packages folder and Sapling will handle the rest.

If you do not call this function at the right time, or at all, pacakges will throw an error and tell you that you have not called this function.

WARNING

This function NEEDS to be called before you call loadServices otherwise packages will error.

DANGER

If you use Actor you will need to call this in every Actor to avoid errors.

Errors

TypeDescription
"You can only call loadPackages one time"You should only call this function once, before you call `loadService`.

fireLifecycle

Sapling.fireLifecycle(
namestring,
...any
) → ()

Utility function to quickly fire a lifecycle, this is so you dont need to create a lifecycle object to fire it and whatever. You can just call this function with the name and any paramaters you want to pass.

createLifecycle

Sapling.createLifecycle(
namestring,
dispatcherBaseDispatcher
) → Lifecycle

Just calls Lifecycle.new

extendBaseDispatcher

Sapling.extendBaseDispatcher() → ()

This function returns a new class that extends the BaseDispatcher. Here is a basic example of a blocking dispatcher:

local BlockingDispatcher = Sapling.extendBaseDispatcher()

function BlockingDispatcher.dispatch(
	self: typeof(BlockingDispatcher),
	name: string,
	...: any
)
	-- The :collectFunctions() is a method on the baseDispatcher class, you can override it yourself
	-- if you really want but there is simply no point to.
	local functions = self:collectFunctions(name)

	-- Loop through all the functiosn and call them
	for _, fn in functions do
		fn(...)
	end
end

return BlockingDispatcher
Show raw api
{
    "functions": [
        {
            "name": "loadServices",
            "desc": "Loads all module scripts under `parent` ignoring anything which isn't a [ModuleScript] instance.",
            "params": [
                {
                    "name": "parent",
                    "desc": "",
                    "lua_type": "Instance"
                },
                {
                    "name": "recursive",
                    "desc": "",
                    "lua_type": "boolean?"
                }
            ],
            "returns": [],
            "function_type": "static",
            "source": {
                "line": 31,
                "path": "packages/sapling/source/init.luau"
            }
        },
        {
            "name": "loadPackages",
            "desc": "This function only needs to be called if you are using any other Sapling Framework packages,\nsimply point it to your Packages folder and Sapling will handle the rest.\n\nIf you do not call this function at the right time, or at all, pacakges will throw an error and tell you that\nyou have not called this function.\n\n:::warning\nThis function **NEEDS** to be called before you call `loadServices` otherwise packages will error.\n:::\n\n:::danger\nIf you use [Actor] you will need to call this in every [Actor] to avoid errors.\n:::",
            "params": [
                {
                    "name": "packagesFolder",
                    "desc": "",
                    "lua_type": "Folder"
                }
            ],
            "returns": [],
            "function_type": "static",
            "errors": [
                {
                    "lua_type": "\"You can only call loadPackages one time\"",
                    "desc": "You should only call this function once, before you call `loadService`."
                }
            ],
            "source": {
                "line": 57,
                "path": "packages/sapling/source/init.luau"
            }
        },
        {
            "name": "fireLifecycle",
            "desc": "Utility function to quickly fire a lifecycle, this is so you dont need to create a lifecycle object\nto fire it and whatever. You can just call this function with the name and any paramaters you want to\npass.",
            "params": [
                {
                    "name": "name",
                    "desc": "",
                    "lua_type": "string"
                },
                {
                    "name": "...",
                    "desc": "",
                    "lua_type": "any"
                }
            ],
            "returns": [],
            "function_type": "static",
            "source": {
                "line": 84,
                "path": "packages/sapling/source/init.luau"
            }
        },
        {
            "name": "createLifecycle",
            "desc": "Just calls [Lifecycle.new]",
            "params": [
                {
                    "name": "name",
                    "desc": "",
                    "lua_type": "string"
                },
                {
                    "name": "dispatcher",
                    "desc": "",
                    "lua_type": "BaseDispatcher"
                }
            ],
            "returns": [
                {
                    "desc": "",
                    "lua_type": "Lifecycle"
                }
            ],
            "function_type": "static",
            "source": {
                "line": 95,
                "path": "packages/sapling/source/init.luau"
            }
        },
        {
            "name": "extendBaseDispatcher",
            "desc": "This function returns a new class that extends the [BaseDispatcher]. Here is a basic example of a blocking dispatcher:\n\n```lua\nlocal BlockingDispatcher = Sapling.extendBaseDispatcher()\n\nfunction BlockingDispatcher.dispatch(\n\tself: typeof(BlockingDispatcher),\n\tname: string,\n\t...: any\n)\n\t-- The :collectFunctions() is a method on the baseDispatcher class, you can override it yourself\n\t-- if you really want but there is simply no point to.\n\tlocal functions = self:collectFunctions(name)\n\n\t-- Loop through all the functiosn and call them\n\tfor _, fn in functions do\n\t\tfn(...)\n\tend\nend\n\nreturn BlockingDispatcher\n```",
            "params": [],
            "returns": [],
            "function_type": "static",
            "source": {
                "line": 123,
                "path": "packages/sapling/source/init.luau"
            }
        }
    ],
    "properties": [
        {
            "name": "Dispatchers",
            "desc": "All the built-in dispatchers lifecycle dispatchers.",
            "lua_type": "any",
            "readonly": true,
            "source": {
                "line": 142,
                "path": "packages/sapling/source/init.luau"
            }
        }
    ],
    "types": [],
    "name": "Sapling",
    "desc": "The main / core package of the Sapling framework.",
    "source": {
        "line": 26,
        "path": "packages/sapling/source/init.luau"
    }
}