Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat[Blend]: Added Attribute Support #442

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
50 changes: 49 additions & 1 deletion src/blend/src/Shared/Blend/Blend.lua
Original file line number Diff line number Diff line change
Expand Up @@ -673,6 +673,54 @@ function Blend._observeTags(tags)
end
end

--[=[
Allows you to add Attributes to a Blend object.

```lua
Blend.New "Part" {
[Blend.Attribute "DamageAmount"] = 50;
};
```

You can also pass Observables in similarly to other Blend API

```lua
Blend.New "ScreenGui" {
[Blend.Attribute "CurrentTime"] = Rx.fromSignal(RunService.Heartbeat):Pipe({
Rx.map(function()
return os.time()
end)
});
};
```

@param attributeName string
@return Observable
]=]
function Blend.Attribute(attributeName)
assert(typeof(attributeName) == "string", "Bad attributeName")

return function(parent, initialValue)
assert(typeof(parent) == "Instance", "Bad parent")

local observe = Blend._observeAttribute(initialValue)

return observe:Pipe({
Rx.tap(function(newValue)
parent:SetAttribute(attributeName, newValue)
end)
})
end
end

function Blend._observeAttribute(attributeValue)
if (Observable.isObservable(attributeValue)) then
return attributeValue
else
return Rx.of(attributeValue)
end
end

--[=[
Mounts Blend objects into an existing instance.

Expand Down Expand Up @@ -1182,4 +1230,4 @@ function Blend.mount(instance, props)
end


return Blend
return Blend