-
Notifications
You must be signed in to change notification settings - Fork 126
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
datascript -> rum/render -> should-update #28
Comments
Old and new are states of component. In simplest case, it you’re not using anything fancy, state just contains arguments this component was created with ( Simple way to solve your problem is to call component with query result as argument:
and use Did I answered your question? |
Here's how I did it so far. The calling component passes an entity, not query result. The reason is I needed the entity as well. It seemed logic to me to pass the entity only, since that would/should be enough:
The component that's being called (the one with the query):
The passed entity itself is not changing, but the result of the query is. I didn't add any mixin in this example. I nest and use this kind of 'pass entity and perform a query' rather often, or at least, I would like to. Since the query is something 'component specific', I'd rather keep in in the component, not in the caller. This way, it makes the code easier to reason about imo - the query is bounded to the component. |
Well, there’s no way around it. If you want to avoid unnecessary rendering you need a component with a lifecycle around the place. In your case you probably need second component that accepts query result and implements
Remember that you’re not avoiding query. You only avoiding rendering of |
Right, I started to realize that :). Of course, the query can't be avoided, rendering can... which was my goal (just to get a hang of rum). I rather like the inner component idea. It's simple, and logic. It'll be pretty easy to make a function or macro to generate both, and possibly adding some functionality in the outer/wrapper component. Great, thx a lot! |
I'm playing around with rum, using the idea of https://github.com/tonsky/datascript-chat - I'm omtting the async/chan part for this example. The application is rather heavily query-based, and I want to implement a :should-update mixin, which will update the components only if the queries are changed (sounds pretty obvious).
I have something like:
Any updates in the database trigger a rum/request-render. Now, the 'should-update' mixin looks like:
However, the 'old' state and the 'new' state are not the old and new state of the transaction (or the component as such), but rather some intermediate states of the component (so it seems to me). The old value is not the 'previous query result' or 'previous state which led to that query result'. What I'd like is to compare the previous result of the query with the new result of the query.
What's the most logic/best way to do this using rum?
The text was updated successfully, but these errors were encountered: