+
Skip to content

daolgierd/State-luau

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

3 Commits
 
 
 
 
 
 

Repository files navigation

State-luau

Super simple state manager (will do proper type checking in the future currently there is no way to make it type safe)

Example

local state = require("../state")

local foo = state.create({
  health = 50,
  items = {
    apple = 1
  }
})

state.middleware(foo, function(data)
  if data.health > 100 then
    data.health = 100
	print("health cannot exceed 100")
  end
  return data
end)

local unsubscribe = state.subscribe(foo, function(data)
  return data.health
end, function(current_health, previous_health)
  print(`current health: {current_health}, previous health: {previous_health}`)
end)

state.set(foo, {
  health = 125,
  items = {
    apple = 2,
  }
})

local items = state.get(foo, "items")
print(`apples: {items.apple}`)

unsubscribe()

About

Super simple state manager

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages

点击 这是indexloc提供的php浏览器服务,不要输入任何密码和下载