Skip to content

Allow immediate invokation for Observer:onChange() #166

@dphfox

Description

@dphfox

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)

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementNew feature or requestready to work onEnhancements/changes ready to be made

    Projects

    Status
    Done

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions