Fork me on GitHub
#untangled
<
2017-04-20
>
claudiu06:04:54

Hi. Has anyone tried Server Side Rendering with , untangled routing ?

claudiu06:04:14

router-instruction & routing-tree-key seem to be missing in the clj file.

claudiu06:04:41

for (uc/get-initial-state TopRouter {}) I get No implementation of method: :initial-state of protocol: #'untangled.client.core/InitialAppState

claudiu06:04:16

Am I doing something wrong or is it not designed for server side rendering ?

gardnervickers12:04:51

@claudiu I believe there’s a function get-initial-state to deal with calling static methods on the server.

claudiu13:04:12

@gardnervickers yep. Seem to work for normal components. But for defrouter or components that have defrouter (the macro from https://untangled-web.github.io/untangled/guide.html#!/untangled_devguide.M15_Routing_UI)

gardnervickers13:04:55

Looks like the router uses get-inital-state, that’s not working for you?

claudiu13:04:05

worked like a charm for cljs 🙂 but in clojure seems to break

claudiu13:04:38

re-writing without the defrouter for now (like in the routing getting started video), since that seems to be the problem as far as I can tell.

gardnervickers13:04:48

Are you sure you’re not calling initial-state anywhere?

claudiu13:04:24

ohh, you’re right. Don’t exactly what I did wrong but seems like if I remove a more complex component it works.

claudiu14:04:28

@gardnervickers thank you, all working now. Was calling uc/initial-state Component {} instead of uc/get-initial-state, strangely enough clojurescript app was working just fine.

tony.kay15:04:07

@claudiu calling the protocol method directly does work in cljs, but it cannot work on the JVM, which is why we provide the additional funciton

tony.kay15:04:39

Javascript lets you dynamically change a class in a way that works for that. JVM does not.

tony.kay15:04:45

The syntax on defui (static protocols) is like saying “I want static methods on a class, but I want them to conform to an interface”…the JVM does not have such a thing. Neither does js, but it is dynamic and can fake it

claudiu19:04:37

@tony.kay cool. Fooled me a bit, since I did not pay close attention there knowing that it worked in cljs 🙂