question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Focusable atoms (optics for this lib)

See original GitHub issue

Hello,

Interesting library!

Would it be possible for you to provide utilities for using this in conjunction with a optics library? My idea for a pretty nice api would be:

const bigAtom: WritableAtom<{myKey: number[]}> = atom({myKey: [1,2,3]})
const focusedAtom: WritableAtom<number> = bigAtom.focus(optic => optic.prop('myKey').index(0))

Or even:

const bigAtom: WritableAtom<{myKey: 10}> = atom({myKey: 10})
const focusedAtom: WritableAtom<number> = bigAtom.prop('myKey').index(0)

The optics library I like is https://github.com/akheron/optics-ts

The idea is that if any of the focused atoms are “set”, then the big atom is updated, leading to a update to the focused atom.

Issue Analytics

  • State:closed
  • Created 3 years ago
  • Comments:10 (4 by maintainers)

github_iconTop GitHub Comments

1reaction
merisbahticommented, Jun 16, 2022

Nope! I think this is the way it’s supposed to work.

If an optional focus (Prism) does not have a value, the setter does nothing.

According to the optics-ts docs (which is used here), here’s the explaination of the optional: https://akheron.github.io/optics-ts/reference-mc/#optional

Create a prism that focuses on the non-undefined subtype of A.

If I’ve understood it correctly, it means that it only focuses on the non-undefined case - if it’s another case, then it does nothing. In this case, it’s undefined, so it does nothing!

I hope that was of help, and if I can assist with something else or elborate further, please ask 😄

1reaction
merisbahticommented, Sep 14, 2020

Looks about right (typing it will be interesting, since some optics are ReadOnly, and some are removable).

Thanks, I think this resolves my issue.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Optics — Jotai, primitive and flexible state management for ...
focusAtom creates a new atom, based on the focus that you pass to it. This creates a derived atom that will focus on...
Read more >
NIST Researchers Develop Miniature Lens for Trapping Atoms
These imprinted surfaces, dubbed metasurfaces, focus laser light to trap, manipulate and image individual atoms within a vapor.
Read more >
An ellipsoidal mirror for focusing of neutral atomic and ...
Manipulation of atomic and molecular beams is essential to atom optics ... have been used to focus a beam of neutral helium atoms...
Read more >
ARC: An open-source library for calculating properties of alkali ...
Abstract: We present an object-oriented Python library for computation of properties of highly-excited Rydberg states of alkali atoms.
Read more >
Single-Atom Trapping in a Metasurface-Lens Optical Tweezer
A metasurface lens is used to trap and image single atoms, ... that leverage ongoing advances in element design libraries and in multilayer ......
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Hashnode Post

No results found