Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/fraktality/atomicbinding
Bind Lua code to an instance hierarchy
https://github.com/fraktality/atomicbinding
Last synced: 7 days ago
JSON representation
Bind Lua code to an instance hierarchy
- Host: GitHub
- URL: https://github.com/fraktality/atomicbinding
- Owner: Fraktality
- License: cc0-1.0
- Created: 2021-08-24T02:12:02.000Z (about 3 years ago)
- Default Branch: main
- Last Pushed: 2022-06-06T07:14:05.000Z (over 2 years ago)
- Last Synced: 2023-08-20T23:21:45.968Z (about 1 year ago)
- Language: Lua
- Homepage:
- Size: 33.2 KB
- Stars: 6
- Watchers: 2
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# ⛓ AtomicBinding
Atomically bind Lua code to a tagged tree of instances.
Uses concepts borrowed from [Destructor](https://github.com/Fraktality/Destructor).# API
## `AtomicBinding.new`
```lua
AtomicBinding.new(
tag: string,
manifest: table,
binding: function(objects: table),
)
```
Create a new atomic binding. Runs the `binding` function when all the instances of the tagged object exist. If the binding function returns a destructor, that destructor is called when the bound object is removed from the DataModel or if any/all of the objects in the manifest are removed from the tagged object.Profiler label: `AtomicBinding.new`
## `AtomicBinding:destroy`
```lua
AtomicBinding:destroy()
```
Undoes the binding completely. Running bindings are cleanly destructed.Profiler label: `AtomicBinding:destroy`
# Usage```lua
local Destructor = require(Modules.Destructor)
local AtomicBinding = require(Modules.AtomicBinding)return AtomicBinding.new("TestObject", { -- TestObject is a tag
a = "A", -- A is a child of TestObject
b = "B", -- B is a child of TestObject
c = "B/C", -- C is a child of B
}, function(objects)
-- Runs when a, b, and c all exist.
local dtor = Destructor.new()
print("Added")
print("A:", objects.a)
print("B:", objects.b)
print("C:", objects.c)
dtor:add(function()
print("Removed")
end)return dtor
end)
```