Fork me on GitHub
#luminus
<
2016-10-25
>
actsasgeek14:10:25

So SPAs seem like a bit of a pain. Is there a tutorial along the lines of “if you grew up on Rails, this is how you’d organization an SPA.”? For some reason, I’m having some difficulty thinking about how the views/data are managed. Most examples are too trivial to give much insight.

actsasgeek14:10:46

I mean it doesn’t literally have to be Rails, it might be a conversion of a multi-page app with REST URLs to an SPA. Otherwise, I’m inclined to give up and just do an MPA.

sveri14:10:40

I am not sure how an SPA relates to Rails? Rails is purely backend, isnt it?

shaun-mahood15:10:32

@actsasgeek: I've been using re-frame and generally have been able to do the views and data very similar to how I would in an MVC style application - there are some differences, but it's more a matter of having the flexibility to choose other models when it makes sense (my background before Clojure was http://ASP.NET MVC, which I believe is reasonably similar to rails). If you have a specific example of what kind of thing you are looking to convert, or something that is giving you trouble, I'd be happy to work through ideas with you.

actsasgeek15:10:33

thanks. I have to think a bit more about what it is that’s a stumbling block for me.

shaun-mahood15:10:05

@actsasgeek: I had the same type of problem and found it pretty hard to communicate exactly what I was struggling with, and one day it kind of clicked - I think it was mainly finding that same mapping you are looking for in a way that made sense. Have you got a particular SPA library you are thinking of using or is it more of a general desire to get more rich interactions on top of what you are doing now? If you haven't looked at it, you might find https://pragprog.com/book/dswdcloj2/web-development-with-clojure-second-edition helpful to get a starting point.

actsasgeek15:10:40

I have the book. My main problem is that it doesn’t quite go into the next “OMG” step.

actsasgeek15:10:38

In a RESTful MPA, we have /users, /products, /orders, /suppliers, etc. and each one has a view…it’s really always the kind of same master/detail pattern plus some AJAX for editing in place maybe if you want to get fancy. You have views, partials, the controllers, etc.

actsasgeek15:10:58

With Compojure, it’s kind of obvious how the server side is managed.

actsasgeek15:10:19

and for an MPA, you can basically do the same client side as you would normally do (with, say, Selmer).

actsasgeek15:10:12

but if you use say, just vanilla Reagent, most examples have everything there in the one page…it doesn’t show switching views from customers to agents, how to handle sorting, editing (is it always a modal pop up). I think that things like secretary and accountant get involved but ¯\(ツ)

shaun-mahood15:10:15

@actsasgeek; Ok, definitely check out https://github.com/Day8/re-framefor that - it's built on top of reagent and makes it pretty easy to get that part going. @yogthos has a good app to use as a getting started example at https://github.com/yogthos/memory-hole/tree/master/src/cljs/memory_hole that has routing and everything in it as well.

frank15:10:50

the re-frame lein template is also a decent example of how to do the above

actsasgeek15:10:17

I actually looked at memory-hole this morning. The main problem I had was that is nothing that describes how it’s wired up. Maybe it’s more obvious if you understand re-frame better.

shaun-mahood15:10:51

Yeah, some understanding of re-frame is definitely required - there's a very good intro video at https://lambdaisland.com/episodes/re-frame that covers the basics well, and the docs are decent (though I've done a bit of work on them so I may be biased), and if there's anything that's unclear to you the #re-frame channel is very helpful.

yogthos16:10:03

I should probably do a post on how memory hole is put together, sounds like it could be useful

actsasgeek17:10:58

cool, thanks.