Skip to content

Commit

Permalink
Added ID to State object.
Browse files Browse the repository at this point in the history
Added the state's ID to its internal table.
  • Loading branch information
SirMallard committed Sep 3, 2024
1 parent 5da4d9c commit b408e7a
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 1 deletion.
1 change: 1 addition & 0 deletions lib/Internal.lua
Original file line number Diff line number Diff line change
Expand Up @@ -647,6 +647,7 @@ return function(Iris: Types.Iris): Types.Internal
return Internal._states[ID]
else
Internal._states[ID] = {
ID = ID,
value = initialValue,
ConnectedWidgets = { [thisWidget.ID] = thisWidget },
ConnectedFunctions = {},
Expand Down
3 changes: 2 additions & 1 deletion lib/WidgetTypes.lua
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,10 @@ export type ID = string

--[=[
@within State
@type State<T> { value: T, get: (self) -> T, set: (self, newValue: T) -> T, onChange: (self, callback: (newValue: T) -> ()) -> (), ConnectedWidgets: { [ID]: Widget }, ConnectedFunctions: { (newValue: T) -> () } }
@type State<T> { ID: ID, value: T, get: (self) -> T, set: (self, newValue: T) -> T, onChange: (self, callback: (newValue: T) -> ()) -> (), ConnectedWidgets: { [ID]: Widget }, ConnectedFunctions: { (newValue: T) -> () } }
]=]
export type State<T> = {
ID: ID,
value: T,
ConnectedWidgets: { [ID]: Widget },
ConnectedFunctions: { (newValue: T) -> () },
Expand Down
5 changes: 5 additions & 0 deletions lib/init.lua
Original file line number Diff line number Diff line change
Expand Up @@ -424,6 +424,7 @@ function Iris.State<T>(initialValue: T): Types.State<T>
return Internal._states[ID]
end
Internal._states[ID] = {
ID = ID,
value = initialValue,
ConnectedWidgets = {},
ConnectedFunctions = {},
Expand Down Expand Up @@ -451,6 +452,7 @@ function Iris.WeakState<T>(initialValue: T): Types.State<T>
end
end
Internal._states[ID] = {
ID = ID,
value = initialValue,
ConnectedWidgets = {},
ConnectedFunctions = {},
Expand Down Expand Up @@ -509,6 +511,7 @@ function Iris.VariableState<T>(variable: T, callback: (T) -> ()): Types.State<T>
end

local newState = {
ID = ID,
value = variable,
ConnectedWidgets = {},
ConnectedFunctions = {},
Expand Down Expand Up @@ -589,6 +592,7 @@ function Iris.TableState<K, V>(tab: { [K]: V }, key: K, callback: ((newValue: V)
end

local newState = {
ID = ID,
value = value,
ConnectedWidgets = {},
ConnectedFunctions = {},
Expand Down Expand Up @@ -633,6 +637,7 @@ function Iris.ComputedState<T, U>(firstState: Types.State<T>, onChangeCallback:
return Internal._states[ID]
else
Internal._states[ID] = {
ID = ID,
value = onChangeCallback(firstState.value),
ConnectedWidgets = {},
ConnectedFunctions = {},
Expand Down

0 comments on commit b408e7a

Please sign in to comment.