-
This library is wonderful! I find myself combining it with RXJS and I'm wondering if there are any reasons why the following pattern would be undesireable compared to, for example, using
|
Beta Was this translation helpful? Give feedback.
Replies: 4 comments 8 replies
-
In general don't view these observables the same as As far as Solid is concerned this part is locked: What triggers the the signals though can be a number of things. They can be the Computeds (which make a bit of a cycle before we do rendering), maybe they can be effects although I don't recommend that. But for the most part they are Async returns (promise resolutions) and user events. So I just view this as matter of how soon you move from the imperative handlers to the reactive system. The simplest event handler is setting a signal. But usually it involves some imperative transformation and setting a signal. RxJS fits nicely as a way of bridging that gap in a declarative way. So I see it more as pushing the signal setting to the end of the transformation change instead of the beginning. In the synchronous case if this was pure Solid it would be the |
Beta Was this translation helpful? Give feedback.
-
Yeah and you might be surprised but I started with observables. I had used signals in Knockout previously and had hopes of unifying things. The problem was I kept coming back to signals. First off generally I wanted my observables Hot, so using BehaviorSubjects everywhere. And that was fine other than by far the biggest advantage of fine-grained reactive is the automatic dependency tracking in terms of templating. It maps to regular expressions. I can write: <div title={`This message is for ${firstName()} ${lastName()}`}>Hi</div> Now I've seen less granular rendering systems basically treat the whole thing as a That all being said I have considered being able to map them to signals in a sneakier compiler way. Like maybe using some sort of naming convention like $. I think TS would choke a lot though if I did that. But I could collect all observables used in the JSX templates that are named as such and convert them into signals in local scope and bind to those instead. Maybe the solution is a pseudo helper function that would signal the change and make TS shut up. like Suspense is an interesting topic in a synchronous system like you find like Solid's async has no meaning so Suspense isn't simply not having a value (as that isn't a real state) as much as intentionally marking that node as pending. And we we do that by using promise factory to pend while the promise is pending. For simple Suspense we are just talking about showing a loading state. Where things get more interesting is Concurrent rendering and Transitions. For instance when a page first loads I have to show the fallback data because I have nothing to show. This is well understood. However, when I navigate to the next page I don't need to recede back to that fallback. With transitions enabled any changed that happens within one gets held from view until all async operations have completed. Although the held page is marked as stale allowing for updates to reflect that. In essence we show the current page while the next page is rendering and loading off screen, and more so we can still apply updates to the in view page without changes in the future branch being seen or clashing. So the part I'm less clear about with Observables is knowing if we should enter transitions. Promises are separate discrete happenings so it is pretty simple to attach these to the transition and then they finish. I imagine there is a good way to do this I just wasn't sure if I provided my resources an observable instead of a promise factory how to handle it. I actually think feeding promises into resources for async might be one of the best and most logical interopt points. Maybe it would make sense to wait for the observable in these cases to complete and view each load as a full stream? Any thoughts. |
Beta Was this translation helpful? Give feedback.
-
This discussion actually reminds me of another question: it's unclear how An example of when this matter would be something like the following: export const MyForm: Component<{ control?: FormControl }> = (props) => {
const control = props.control || new FormControl('defaultValue');
const [value] = toSignal(control.observe('value'));
return (
<div>
<label for="test-control">My input</label>
<input name="test-control" type="text" oninput={e => control.setValue(e.currentTarget.value)} />
</div>
);
}; If |
Beta Was this translation helpful? Give feedback.
-
Re: @ryansolid
So if I'm understanding this correctly, I can observe a specific property on a component via export const MyForm: Component<{ control?: FormControl }> = (props) => {
const controlSignal = createMemo(() => props.control || new FormControl('defaultValue'));
const controlObservable = observable(controlSignal);
const [value] = toSignal(
toRXJS(controlObservable).pipe(
switchMap(c => c.observe('value'))
)
);
return (
<div>
<label for="test-control">My input</label>
<input name="test-control" type="text" oninput={e => controlSignal().setValue(e.currentTarget.value)} />
</div>
);
}; Is this correct? It makes me wonder if In my case, the confusion is definitely stemming from the fact that props are typed as a plain object, yet apparently they are reactive. If props were typed as signals (i.e. |
Beta Was this translation helpful? Give feedback.
The main reason for
createEffect
is to handle stuff after render like interactions with the DOM. I don't see any problem with this. The only place where I feel there are some gaps are that I haven't really figured out how to make Observables play into stuff like Suspense. Promises are easy since you know they are single purpose. I'm unclear if we wired observables in how to determine when we should consider things stale.I mean yes... but that's true of anything right. I tend to not use
createEffect
because I want to not block rendering, but simply because that use case is where I tend to use it. If anything, if there are recalculations involved I'd rather do it increateComputed
so t…