Skip to content

Commit

Permalink
Added changed state event.
Browse files Browse the repository at this point in the history
  • Loading branch information
SirMallard committed Dec 10, 2024
1 parent 717a016 commit d6fadb5
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 0 deletions.
12 changes: 12 additions & 0 deletions lib/Internal.lua
Original file line number Diff line number Diff line change
Expand Up @@ -161,6 +161,7 @@ return function(Iris: Types.Iris): Types.Internal
@within State
@method onChange<T>
@param callback (newValue: T) -> ()
@return () -> ()
Allows the caller to connect a callback which is called when the states value is changed.
Expand All @@ -177,6 +178,17 @@ return function(Iris: Types.Iris): Types.Internal
end
end

--[=[
@within State
@method changed<T>
@return boolean
Returns true if the state was changed on this frame.
]=]
function StateClass:changed<T>(): boolean
return self.lastChangeTick + 1 == Internal._cycleTick
end

Internal.StateClass = StateClass

--[[
Expand Down
1 change: 1 addition & 0 deletions lib/WidgetTypes.lua
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ export type State<T> = {
get: (self: State<T>) -> T,
set: (self: State<T>, newValue: T, force: true?) -> (),
onChange: (self: State<T>, funcToConnect: (newValue: T) -> ()) -> () -> (),
changed: (self: State<T>) -> boolean,
}

--[=[
Expand Down

0 comments on commit d6fadb5

Please sign in to comment.