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

Add createLens primitive #453

Open
nathanbabcock opened this issue May 28, 2023 · 1 comment
Open

Add createLens primitive #453

nathanbabcock opened this issue May 28, 2023 · 1 comment
Labels
Primitive Proposal For discussing a primitive proposition and the API design

Comments

@nathanbabcock
Copy link

nathanbabcock commented May 28, 2023

Describe The Problem To Be Solved

Utilities for working with nested reactivity in a modular way.

See previous discussion:

Originally described by @clinuxrulz:

Say our application state holds a collection of states of things in the tabs of the application. It can be handy to have a Lens to focus on a subset of the state in order to provide a store for use by the UI in the tabs state. So that rhe end-user does not need to alway push state changes to top level (under the hood the state still reaches the top, it is just hidden boiler plate).

Suggest A Solution

Proposed primitives:

  • createLens - Given a path within a Store object, return a derived or "focused"
    getter and setter pair.

  • createFocusedGetter - The first half of the lens tuple; a derived Signal
    using path syntax on an object.

  • createFocusedSetter - The second half of the lens tuple; a Setter
    for a specific path within a Store.

I've started a PR to explore this concept (WIP): #452

It's essentially just syntactic sugar on top of regular Stores, with some tricks to maintain Typescript support.

In previous discussion people theorized about a performance benefit from this approach as well, by caching a partially applied path within the Store object -- for example: solidjs/solid#506 (comment).

I'm not as familiar under the hood of how the Store works, so my goal will be the replicate the intended DX and then unit test thoroughly enough that someone else could come in and work some performance magic. For now it is Lens-like DX with the same behavior/performance as a regular Store.

I'm also curious to get people's thoughts on:

  • Does this seem useful?
  • Are the types correct?
  • What tests are missing?

Cheers 🍺

@nathanbabcock
Copy link
Author

@thetarnav thetarnav added the Primitive Proposal For discussing a primitive proposition and the API design label Aug 29, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Primitive Proposal For discussing a primitive proposition and the API design
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants