State Watcher - Display your Table with value and get changes connected to it!

State-Watcher

This module gives the table sort of like an event to display the Value that’s been changed.
The Module is inspired off ReplicaService just without the Networking System which I’ll be working on Soon.

The State-Watcher doesn’t have any specific Paradigm to follow, all it does is apply Methods to the table you created and display the changes :slight_smile:

The Module itself doesn’t have setter() or getter() to set each values or get the values, you just basically concatenate them

But the only thing that it’s not allowed to do is constructing an empty list, let’s say you’d like to create a Playerlist or a leaderboard and then you proceed to add a new Key
It would not trigger that changes. Which I’ll look forward soon.

Anyways, let’s get straight-forward on how to use the State-Watcher

Installation

:link:: GitHub - raydjs/State-Watcher: This module gives the table sort of like an event to display the Value that's been changed.

NOTES: IF you prefer setter() this is the source

:link:: GitHub - raydjs/state_with_set_gets

Classes

Currently there is only 2 Class

  • State.create(anyTable: table) -> table

    • The create function constructs a table that’s already been applied with methods to trigger the values.
  • State.extension -> {inject}

    • The extension is a table that consist only 1 sub-class which is inject the given argument must be created from State.create in which it will give you a Table
    • State.extension.inject(State.create)

Methods

The existant methods are:

  • inject:Watch(path, callback)
  • This will apply a method to attach to the value you want to watch.
  • inject:Destroy()
  • This method is optional if you want to destroy the :Watch() method

Usage

local myTable = kiroState.create {
	["Combat"] = {
		isActive = false,
	},

	["PlayerInfo"] = {
		isRagdolled = false,
		isRunning = false,
		Health = 100,
		Name = "kiro",
	},
}

local inject = kiroState.extension.inject(myTable)

inject:Watch({ "Combat", "isActive" }, function(value: boolean)
	print(value)
end)

inject:Watch({ "PlayerInfo", "isRagdolled" }, function(value: boolean)
	print(value)
end)

inject:Watch({ "PlayerInfo", "isRunning" }, function(value: boolean)
	print(value)
end)

inject:Watch({ "PlayerInfo", "Health" }, function(value: number)
	print(value)
end)

inject:Watch({ "PlayerInfo", "Name" }, function(value: string)
	print(value)
end)

myTable.Combat.isActive = true
myTable.Combat.isActive = false
myTable.PlayerInfo.isRagdolled = true
myTable.PlayerInfo.isRagdolled = false
myTable.PlayerInfo.isRunning = true
myTable.PlayerInfo.isRunning = false
myTable.PlayerInfo.Health -= 10
myTable.PlayerInfo.Name = "kiro legend"

inject:Destroy({ "PlayerInfo", "Name" })
inject:Destroy({ "PlayerInfo", "Health" })
inject:Destroy({ "PlayerInfo", "isRunning" })
inject:Destroy({ "PlayerInfo", "isRagdolled" })
1 Like

I love the idea of a state package but not sure what you are trying to get at here. The way the example looks is just too complicated for a quick and easy use case. Most commonly (if not just only) I would use this UI as I dislike libraries.

It feels as if I’m just listening to a signal that gets fired when it changes, which is not what a state is at all. A state should allow something to be updated in real time without any developer interference.

Not recommended to use this for UI such as Fusion, React.