-
Notifications
You must be signed in to change notification settings - Fork 2
⭐ Implement State.fromValue #20
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
base: Master
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change | ||||
---|---|---|---|---|---|---|
|
@@ -405,6 +405,38 @@ function State.Interface.fromAttribute(object: Instance, attribute: string): Sta | |||||
return stateObject | ||||||
end | ||||||
|
||||||
--[=[ | ||||||
@function fromValue | ||||||
@within State | ||||||
|
||||||
@param object Instance & { Value: any? } | ||||||
|
||||||
@return State | ||||||
|
||||||
Wrapper for `State.new` however wraps around a Roblox Instance, the State object will always have the latest value. | ||||||
|
||||||
```lua | ||||||
local object = State.fromValue(workspace.object) | ||||||
|
||||||
... | ||||||
``` | ||||||
]=] | ||||||
function State.Interface.fromValue(object: Instance & { Value: any? }): State | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I had it as ValueBase at first but opted for Instance instead as it adds nothing; none of the Value classes such as I have no problem conforming it but I thought I'd give my thoughts 🍀 |
||||||
assert(object.Value, "instance must be a Value object!") | ||||||
|
||||||
local stateObject = State.Interface.new(object.Value) | ||||||
|
||||||
local valueConnection = object:GetPropertyChangedSignal("Value"):Connect(function() | ||||||
stateObject:Set(object.Value) | ||||||
end) | ||||||
|
||||||
stateObject.Destroyed:Once(function() | ||||||
valueConnection:Disconnect() | ||||||
end) | ||||||
|
||||||
return stateObject | ||||||
end | ||||||
|
||||||
--[=[ | ||||||
@function is | ||||||
@within State | ||||||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.