FAQ
Hello
Recently i was experimenting with Clojure and web stack and created kind of
non-standart web app. It doesn't use routing there are no any urls there.
This app is mostly "One page apps". Instead of routes i used id's and
classes.
Let me explain:
I used "Noir" and "fetch" libs and logic of interaction was something like
this:


User clicks link with some id -> i bind this even to js/cljs function ->
this function calls function on the server
-> that returns appropriate HTML code -> cljs function inserts that code
at right place in the page.

Function on the server calls controller function -> controller function
gets data and insert that data into the template -> and returns HTML code
as string


app.cljs file
-------------------------
(defn show-user-info [mid e]
(prevent e)
(let [a (attr ($ mid) :profile)]
(.dialog ($ "#user-info-box") "open")
(remote (show-user a) [result]
(inner ($ "#user-info-box") result)))
)

This method calls show-user function on the server and send it appropriate
arguments.

main.clj file on the server
--------------------------
;Show user profile info

(defremote show-user [a]
(pa/user-profile-pa a)
)

This function returns HTML code as a string

partials.clj file
----------------------------------
(defpartial user-profile-pa [uid]
(map user-profile-box (mprof/get-profile uid))
)

This function joins data and template via *map* function. It is something
like controller.

user-profile-box is a template like so:
------------------------
(defpartial user-profile-box [{:keys [uname city site business profimg age
f1]}]
[:ul
[:li
[:img {:src profimg }]]
[:li (str "Name: " uname)]
(if city [:li (str "City: " city)])
(if business [:li (str "Business: " business)])
(if site [:li (str "Site: " site)])
(if age [:li (str "Age: " age)])
]
)
This partial gets data from (mprof/get-profile uid) call


I found this approach pretty insteresting and simple though it's not mature
and can be improved a lot. What you think about that ?

I've seen this approach in Lift - scala framework and something like this
is implemented in Meteor.

--
--
You received this message because you are subscribed to the Google
Groups "Clojure" group.
To post to this group, send email to clojure@googlegroups.com
Note that posts from new members are moderated - please be patient with your first post.
To unsubscribe from this group, send email to
clojure+unsubscribe@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/clojure?hl=en
---
You received this message because you are subscribed to the Google Groups "Clojure" group.
To unsubscribe from this group and stop receiving emails from it, send an email to clojure+unsubscribe@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.

Search Discussions

Related Discussions

Discussion Navigation
viewthread | post
Discussion Overview
groupclojure @
categoriesclojure
postedFeb 26, '13 at 7:32p
activeFeb 26, '13 at 7:32p
posts1
users1
websiteclojure.org
irc#clojure

1 user in discussion

Yakovlev Roman: 1 post

People

Translate

site design / logo © 2022 Grokbase