Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

How to access the state hook of an element? #26

Open
EngineerSmith opened this issue Nov 21, 2021 · 0 comments
Open

How to access the state hook of an element? #26

EngineerSmith opened this issue Nov 21, 2021 · 0 comments

Comments

@EngineerSmith
Copy link

EngineerSmith commented Nov 21, 2021

I've been reading through the documents, and I'm trying to access the state. My current work around is as followed

-- eFactory
local helium, useState = ..., ...
return helium(function(parameter, view)
  parameter.r = parameter.r or 1
  local state = useState(parameter)
  return function()
    love.graphics.setColor(state.r,1,1)
    love.graphics.rectangle("fill", 0, 0, view.w, view.h)
  end
end)
---- main.lua
-- Skips creation of scene to make example simple
local state = {}
local e = eFactory(state, ...)
love.update = function(dt)
  state.r = state.r + 0.1 * dt
  while state.r > 1 then state.r = state.r - 1 end
end
love.draw = ...

Is there a recommended way of how to access the element's state outside of the element creation than passing a table through parameter or using parameter itself?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant