Skip to content

Store for complex objects #10

@s1n7ax

Description

@s1n7ax

Note:
object == lua table in this ticket

Problem:

  • create_signal is fine for primitive values and state that only lives within the same component or few children of it. Things are not that simple when you want share the same state to many components spread through out the application. Prop drilling is one option and good in terms of re-usability of components though it's could become a complete mess.
  • Passing an complex object to create_signal works but updating it makes every component/effect using that signal to re-render even if the update is a partial update.

Possible Solutions:

  • Write a wrapper for Lists and Maps
  • Redux.useSelector like hook to extract the used part of the store and trigger a re-render only if the value is changed

I have tried

Using wrapper for key, value stores using __index & __newindex.

Pros:

  • Exact dependencies of an object can be tracked & only the effects that's using the dependencies can be used

Cons:

  • Though you can index, reality is, it's not the initial object you passed. So store or part of it can not be treat as an object. For example passing it to pairs will through an error.
  • Updating the values should be done through a dict-node & value has to be indexed before a new value is assigned in order __newindex to be called.

Metadata

Metadata

Assignees

Labels

enhancementNew feature or request

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions