Skip to content
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

How to use daiquiri.core/html ? #257

Open
xlisp opened this issue Apr 28, 2023 · 9 comments
Open

How to use daiquiri.core/html ? #257

xlisp opened this issue Apr 28, 2023 · 9 comments

Comments

@xlisp
Copy link

xlisp commented Apr 28, 2023

Can not find this function :
image

@tonsky

@xlisp
Copy link
Author

xlisp commented Apr 28, 2023

In the rum version "0.12.10".

@tonsky
Copy link
Owner

tonsky commented Apr 28, 2023

(defmacro html
"Compile the Hiccup `form`. Always produces code that evaluates to
React elements."
[form]
(compiler/compile-html form &env))

@xlisp
Copy link
Author

xlisp commented Apr 28, 2023

Can this function only be required by the backend and then used?
Why does my front-end cljs require daiquiri.core, but the daiquiri.core/html function cannot be found.
@tonsky
I want to use a function similar to reagent as-element in rum: https://github.com/reagent-project/reagent/blob/master/doc/InteropWithReact.md

@tonsky
Copy link
Owner

tonsky commented Apr 28, 2023

I don’t know. @roman01la do you know this on the top of your head?

@xlisp
Copy link
Author

xlisp commented Apr 28, 2023

I am quoting in the wrong way, because this is a macro, so I have to use require-macro😂, I searched the github code, and found that there is no project using daiquiri.core, I thought this thing can not be used, so I asked you.
@tonsky

(:require-macros
   [daiquiri.core :refer [html]])

@xlisp
Copy link
Author

xlisp commented Apr 28, 2023

Another problem is that if I use rum and datascript as the front end, if I need to update the datascript data, I will update the rum component responsively:
The first way is to use (rum/react datascript-conn), like this code:
https://github.com/tonsky/datascript-chat/blob/gh-pages/src/datascript_chat/ui.cljs#L134 .
The second way is to use d/listen, and any data change will execute the rum update component.
I'm worried about performance issues with the first approach. Do you have any good recommended method? If there are a lot of datascript responsive update components. @tonsky Thanks ❤️

@tonsky
Copy link
Owner

tonsky commented Apr 30, 2023

Yes, I was thinking about fine-grained reactivity for DataScript, but nothing was implemented. Maybe one day :)

@xlisp
Copy link
Author

xlisp commented Apr 30, 2023

@tonsky

For partial update components, there are actually some solutions, which I have tried. A specific datascript data can be updated to achieve partial real-time update. Like this project:
https://github.com/mpdairy/posh/blob/master/src/posh/plugin_base.cljc#L47

(defn posh! [dcfg & conns]
  (let [posh-atom (atom {})]
    (reset! posh-atom
            (loop [n 0
                   conns conns
                   posh-tree (-> (p/empty-tree dcfg [:results])
                                 (assoc :ratoms {}
                                        :reactions {}))]
              (if (empty? conns)
                posh-tree
                (recur (inc n)
                       (rest conns)
                       (let [db-id (keyword (str "conn" n))]
                         (p/add-db posh-tree
                                   db-id
                                   (set-conn-listener! dcfg posh-atom (first conns) db-id)
                                   (:schema @(first conns))))))))))

It uses a large posh-atom (reagent) and posh-tree as a proxy, puts datascript data into their memory, and then listens to the modified data of datascript through d/listen!, and modifies it through posh-tree posh-atom, so as to realize the partial effect of responsive update.

@xlisp
Copy link
Author

xlisp commented Apr 30, 2023

But I think the implementation of the posh project is okay with fewer nodes. If there are too many nodes, there will be performance problems. Because all datascript data will be placed in reagent posh-atom, resulting in too much memory usage. This is a very rough way. Although it can look more elegant to use.
But if you don't do this, you need to write a lot of d/listen! Listening to different data changes and then updating the corresponding components is not so elegant for users.
I think the advantages of rum can be combined with datascript to better solve the partial update problem, or provide such other libraries.

@tonsky what do you think? ;-P

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants