Replies: 1 comment
-
Another thoughts: const filterAtom = atom("", "filterAtom");
const aResource = reatomResource((ctx) => {
const filter = ctx.spy(filterAtom);
return ctx.schedule(() => fetch(`/a?${filter}`).then((res) => res.json()));
});
const bResource = reatomResource((ctx) => {
const filter = ctx.spy(filterAtom);
return ctx.schedule(() => fetch(`/a?${filter}`).then((res) => res.json()));
});
const cResource = reatomResource(async (ctx) => {
const a = await Promise.all([ctx.spy(aResource), ctx.spy(bResource)]);
return a.map((data) => data.b);
});``` |
Beta Was this translation helpful? Give feedback.
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
About
So, after a few feedbacks (#578) we found a few problems with update hooks, which makes it not obvious and not useful.
After some investigations and have an inspiration from signals effect we found a nice - simple and powerful API which could solve a lot of cases and made it obvious.
reaction
- it is kind a signal effect, but with manual setup. It is look and work just like an atom, but the interface helps you to use it for a logic effects. Reaction accepts a callback with reactivespy
and returns a special kind of action, which call activate the callback and returns a deactivate (unsubscribe) callback.Example
To run
reactSuggestion
you should call it as a regular action and it will return an unsubscribe function. Probably, you want to do it withonConnect
.The most important thing is that a combination of a few atom dependencies. For
onChange
codestyle you need extracombine
operator with unobvious and dangerous behavior around update propagation.reaction
handle it perfectly, as it uses commonspy
API and force you to create a subscription.Implementation
The whole implementation is a super tiny, the bundle overhead is less than 100 gzip byte.
Reuse the pattern in other packages
We expect to reuse the "reaction" pattern throughout the ecosystem.
Beta Was this translation helpful? Give feedback.
All reactions