f / f/react-wait

Waiters composition

Abierto
#12 1 comentario 1 reacción 0 asignados Ver en GitHub
Lenguaje dominante
JavaScript
Estrellas
306
Forks
28
Métricas de merge de PR
Sin PR fusionados en 30 d

Descripción

I've been using the library for a while and I noticed that I could simplify my code with something like composing of the waiters. For example, given that I have two waiters `bar` and `baz`, I would like to have `foo` waiter that is waiting if one of `bar` or `baz` is waiting.

#### Motivation

Now, first I was thinking about adding array argument support to `isWaiting` so that I could call `isWaiting(["foo", "bar"])` or a bit more explicit convenience function `isAnyWaiting(["foo", "bar"])`.

But after looking into my code I realized it's not enough. In my case, I have some big component
`Foo` rendering smaller components `Bar` and `Baz` that wait on each other. That works fine with current API. It gets more convoluted when you would like to have some other component `Qux` that doesn't exactly want to know about the lower-level ones but needs to know if `Foo` or any of it's children waits. So currently in `Qux` you would need to write

```js
const isFooWaiting = isWaiting("baz") && isWaiting("baz")
```
That's not ideal because `Qux` needs to know too much about `Foo` internals.

#### Proposal

Create a separate method that will create a new waiter if one of the child waiters is waiting. It could be similar in usage to `createWaitingContext`:

```js
const { compose } = useWait();
const { isWaiting } = compose("Foo", ["Bar", "Baz"])
```
* `Foo` is a waiter, you can check if it's waiting with `isWaiting("Foo")`
* `Foo` is always waiting if `Bar` or `Baz` is waiting.
* the open question is should you be able to manually start and end a composed waiter?

#### Anternative idea

Maybe instead adding a `compose` method, we could compose `Waiter` providers? It's just an idea, I don't know if it's possible or makes sense but provier could have an optional name and be a child of another warapper like this?

```jsx


// ...

```
Then if the inner's `anyWaiting()` is `true`, `foo` is waiting in the outer waiter?
Again, it's just an idea.

Guía de contribución

No hay ninguna guía de contribución indexada para este repositorio

Línea de trabajo

Empieza leyendo la useWait API y createWaitingContext; después, inspecciona el enfoque del proveedor Waiter descrito en el issue. Define cómo los waiters compuestos propagan el estado de sus hijos y si se admite el inicio/finalización manual; se considera terminado cuando el comportamiento de la API y los casos límite están especificados y verificados respecto al comportamiento existente del waiter.

Escrito por el modelo de indexación a partir del texto del issue.

Evaluación

Stack tecnológico
javascript, react
Área
frontend
Tipo de issue
Nueva funcionalidad
Dificultad
5/5
Tiempo estimado
Más de una semana
Estado de actividad
Estancado
Claridad
Necesita aclaración
Aptitud para principiantes
25/100

Recibe los nuevos issues en tu correo

Un resumen breve de issues de GitHub para principiantes.