Upgrade to Pro — share decks privately, control downloads, hide ads and more …

Simple Front-End Development with Pedestal

Chad Taylor
December 04, 2013

Simple Front-End Development with Pedestal

These are the slides for the presentation I gave to the HuntFunc user group in December 2013.

Chad Taylor

December 04, 2013
Tweet

More Decks by Chad Taylor

Other Decks in Programming

Transcript

  1. A collection of libraries for web development in Clojure and

    ClojureScript A collection of tools to help ease the development by keeping concerns separated
  2. My goals are two-fold: Prepare you for the tutorial if

    you haven’t tried it Clarify some of the fuzzier details if you have
  3. These are mostly view-concerned. Pedestal provides more infrastructure for building

    large applications, supporting separation of concerns throughout the development cycle. Pedestal decouples the concept of rendering from the DOM and even decouples event registration.
  4. This results in more flexibility - ranging from automatic rendering

    to building tools that record and playback application events. Since the application model is decoupled from the DOM, the application is also more testable.
  5. These break an application down into the familiar MVC model.

    Mutation is handled locally within services and controllers. Complexity begins to ramp when dealing with dynamic data (e.g., from web sockets). Pedestal breaks the problem down differently. It constrains mutation to be localized within the Pedestal library and keeps complexity low, even with highly interactive applications.
  6. Another way to say this is that X.js makes development

    easy, while Pedestal makes it simple. Complexity with X.js can ramp quickly - especially when building highly interactive applications. Complexity with Pedestal stays relatively flat.
  7. Messages can theoretically come from anywhere, such as an AJAX

    call resolving or an event in the UI occurring
  8. Messages have a type and a topic type - The

    type of the message topic - The data with which the message is concerned path in data model
  9. When a message is being handled, we want to transform

    the data element in the data model based on the message. To do this, we write a pure function and let Pedestal handle the data model mutation for us.
  10. current value in data model the transform logic protect against

    nil behavior.clj A Transform Function the message from the input queue
  11. But...how do I tie the message to use that transform?

    You configure the application Dataflow
  12. Dataflow is... described implicitly in the tutorial the app wiring,

    connecting functions & data sometimes used as a proper noun, sometimes not (I will strive to use it as a proper noun) defined with a map
  13. Dataflow definition Since the definitions are in a vector, order

    matters. A message is handled by the first matching transform. behavior.clj
  14. ...but I {{ mustache }}, what about templates? No worries,

    we don’t need any right now. Why the HTML not?! Pedestal provides some pretty cool tools that help keep application logic and rendering separated.
  15. To show the aspects, move the cursor to the page’s

    lower-right. http://localhost:3000
  16. Wait, I’ve got it! If the input queue started out

    empty, then the data model must be empty!
  17. Well, now we need to define an application model. •

    distinct model for rendering concerns • derived from data model
  18. The application model is defined by emitted deltas generated from

    functions that observe changes to the data model. The deltas are passed to the renderer.
  19. Most of the time, this is just a pass-through. Pedestal

    provides a default emitter for this case.
  20. a set of paths in the data model to watch

    for changes a function to generate application model deltas from the data model changes
  21. a higher-order function that creates an emitter function a prefix

    to attach to changed nodes (e.g., [:my :counter] in the data model becomes [:main :my :counter] in the application model)
  22. HINT The term Data UI is somewhat misleading. It renders

    the application model, not the data model. It took me awhile to pick up on this little detail... Now, an aside:
  23. If you look at your browser’s developer tools, you can

    see the rendering deltas in the console.
  24. To do this, we need to tell the renderer that

    it can initiate a transform to the application model by sending messages to the input queue. We achieve this by sending a delta to the renderer informing it about the transform.
  25. indicates that the delta should be sent at application startup

    the function that will provide the deltas
  26. Now we’re getting somewhere! Now, if only we could make

    it so that my designer won’t puke when she sees it...
  27. Okay, so the markup appears fine...but how can I make

    sure that everything is wired up correctly?
  28. In the Data UI, press Alt-Shift-R. (Yes, even on OS

    X.) Press the button a few times, then press Alt-Shift-R again. When prompted, provide a :keyword and a description of what you did during the recording session.
  29. This creates a file with all the deltas saved into

    it. The deltas can be replayed later.
  30. Now go to the “Render” aspect. runs all deltas immediately

    runs one transaction at a time (press -> to advance) runs one delta at a time (use <- and -> to update)
  31. Now, imagine a really hard-to-duplicate sequence of events that you

    want to ensure are rendered properly. This tool lets you write that sequence, and then step through it!
  32. No more wasting time attempting to generate the situation in

    the browser. No more succumbing to non-repeatability. No more crying yourself to sleep while wondering how to duplicate that bug deep down in the dark asynchronous abyss in your project.
  33. Send the messages from the previously defined :transform-enable to be

    sent to the input queue when “#inc-button” is clicked.
  34. Please check out the tutorial. It is super awesome. But

    keep this presentation handy, too! It will help with some of the tricky bits.