Created
May 16, 2017 10:44
-
-
Save practicalli-johnny/35f58e42ae1df3269261436b667a273c to your computer and use it in GitHub Desktop.
ClojureScript Reagent - conference app - REPL experiements
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(ns conference-reagent.core | |
(:require [reagent.core :as reagent :refer [atom]])) | |
(enable-console-print!) | |
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; | |
;; Conference data | |
(def john {:title "My not so secret Spacemacs addiction" | |
:description "Sharing my journey into unleashing the power of Spacemacs to drive my digital world" | |
:speaker-name "John Stevenson" | |
:speaker-biography "There's a frood who really knows where his towel is." | |
:twitter-handle "jr0cket" | |
:github-handle "jr0cket" | |
:speakers-website "http://jr0cket.co.uk"}) | |
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; | |
;; Application State | |
(defonce app-state (atom {:conference-name "ClojureX" | |
:schedule []})) | |
(defonce schedule-counter (atom 0)) | |
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; | |
;; Helper functions | |
(defn add-session [details] | |
(let [talk-id (swap! schedule-counter inc)] | |
(swap! app-state assoc :schedule {:id talk-id :title (:title details)}))) | |
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; | |
;; Components | |
(defn build-conference [] | |
[:div | |
[:h1 (:conference-name @app-state)] | |
(for [talk (get @app-state :schedule)] | |
[:div (:title (apply hash-map talk))])]) | |
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; | |
;; Render components | |
(reagent/render [build-conference] (js/document.getElementById "app")) | |
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; | |
;; Interact with the REPL | |
;; (in-ns conference-reagent.core) | |
#_(swap! app-state assoc :text "I feel the power of the REPL") | |
;; Experiment with the model for state | |
#_(swap! app-state assoc :schedule []) | |
#_(swap! app-state update :schedule conj {:title "Opening Keynote" | |
:description "Something very inspirational" | |
:twitter-handle "jr0cket" }) | |
;; Show the current app-state | |
#_@app-state | |
#_(swap! app-state assoc :schedule conj john) | |
#_(swap! app-state assoc :schedule conj {:title "My not so secret Spacemacs addiction" | |
:description "Sharing my journey into unleashing the power of Spacemacs to drive my digital world" | |
:speaker-name "John Stevenson" | |
:speaker-biography "There's a frood who really knows where his towel is." | |
:twitter-handle "jr0cket" | |
:github-handle "jr0cket" | |
:speakers-website "http://jr0cket.co.uk"}) | |
#_(reset! app-state {:conference-name "ClojureX" | |
:schedule []}) | |
(defn reset-app-state! [] | |
(reset! app-state {:conference-name "ClojureX" | |
:schedule []})) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment