Fusion
Fusion copied to clipboard
Allow immediate invokation for `Observer:onChange()`
Oftentimes the same function will be used for initialising an observer and updating it in response to a change:
local theValue = Value(5)
local function updateFoo()
foo.Color = theValue:get()
end
updateFoo()
Observer(theValue):onChange(updateFoo)
Sometimes this may not be expressed explicitly:
local theValue = Value(5)
foo.Color = theValue:get()
Observer(theValue):onChange(function()
foo.Color = theValue:get()
end)
To reduce code duplication and the potential for errors, we could introduce a shorthand which immediately invokes the callback function in a spawned thread:
local theValue = Value(5)
Observer(theValue):onBind(function()
foo.Color = theValue:get()
end)
I have a wrapper function for just this, and I basically use it in 99% of my Observer uses, so it'd be really nice addition!
This can be closed due to the above being merged!