Fork me on GitHub
#reagent
<
2021-05-26
>
Oliver George08:05:39

I’d like to set up a react component library and use it with my reagent app

Oliver George08:05:03

Can anybody recommend build tooling. Is Babel enough? Rollup sounds about right, right?

Oliver George08:05:43

I think I just need the basics really. Prefer not to invest heavily in fancy / complicated / transient stuff

Oliver George08:05:12

(Having said that I am planning to use StorybookJS)

Oliver George08:05:07

(The react documentation points to other tools for component library setup)

p-himik08:05:09

You mean it has JSX files and no compiled JS files? If so, then I know only of this guide for shadow-cljs: https://shadow-cljs.github.io/docs/UsersGuide.html#_javascript_dialects

Oliver George10:05:51

Thanks for that link. Definitely ticks the boxes.

Quentin Le Guennec16:05:18

Hello, is there a way to execute a side effect once when an atom holds value A, and never again for subsequent resets of that atom at the same value A?

Noah Bogart16:05:30

lol second atom?

Quentin Le Guennec16:05:33

Not sure if I'm being clear

Noah Bogart16:05:31

or make it a map: (atom {:initial true :value 0}) ... (swap! a #(if (:initial %) (assoc % :initial false :value 100) %))

Quentin Le Guennec16:05:04

Not sure if that would help

Quentin Le Guennec16:05:29

I might just explain what I'm trying to do, it would be more explicit

👍 3
Quentin Le Guennec16:05:50

I need to fetch n pages in some api, but I can fetch page + 1 only if page is loaded and some side effect has been triggered that depends on page

Quentin Le Guennec16:05:24

imperatively, fetch page, wait for the fetch to complete, print page on the screen, fetch page + 1, repeat

Quentin Le Guennec16:05:45

"fetch" returns an atom

Quentin Le Guennec16:05:33

so somehow, "fetch page + 1" is a reaction on "fetch page", but reacting on it would mean re-executing the side-effect, which is unwanted.

Quentin Le Guennec16:05:55

Does that make sense?

p-himik17:05:16

Not very much, to be honest, Why does a fetch function return an atom in the first place?

Quentin Le Guennec17:05:42

it returns the result of the fetch, either "loading", either data

p-himik17:05:09

I'm not entirely certain I completely understand what you're doing, but to me that, plus you saying that a reaction executes side-effects, seems like abusing Reagent ratoms/reactions system.

Quentin Le Guennec17:05:10

yeah, I'm aware that we extended the initial use of ratoms quite a lot

lilactown17:05:37

using reactions for this is really difficult. my recommendation would be to use promises or some other method for composing these async operations

Quentin Le Guennec17:05:21

I think I could get around it using track

emccue18:05:05

@quentin.leguennec1 add a watch function that is memoized?

Quentin Le Guennec18:05:59

@emccue I thought that was one of the uses of track

emccue18:05:23

well track fires on any change

emccue18:05:43

if you want it to only ever fire once for a given state you need another box of state

emccue18:05:56

hence memoizing the callback

Quentin Le Guennec18:05:18

"Every use of track with the same arguments will only result in one execution of the function. E.g the two uses of `@(r/track people)` in the example above will only result in one call to the people function (both initially, and when the state atom changes)."

emccue18:05:48

I thin that is more about saying that the function will only be triggered once per change

emccue18:05:54

not per value ever encountered