Skip to content

Instantly share code, notes, and snippets.

@jdkealy
Created July 15, 2014 16:58
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jdkealy/f8b6db5829406fc2030d to your computer and use it in GitHub Desktop.
Save jdkealy/f8b6db5829406fc2030d to your computer and use it in GitHub Desktop.
(ns ptv.scratch
(:require-macros [cljs.core.async.macros :refer [go alt!]])
(:use [domina :only [by-id value]])
(:require
[goog.dom :as gdom]
[cljs-http.client :as http]
[cljs.core.async :refer [put! <! >! chan timeout map<]]
[om.core :as om :include-macros true]
[sablono.core :as html :refer-macros [html]]
[om.dom :as dom :include-macros true]))
(enable-console-print!)
(def app-state (atom {}))
(defn component-one [data owner opts]
(reify
om/IShouldUpdate
(should-update [this _ next-state]
(prn [(om/get-render-state owner) (om/get-state owner) next-state]) true)
om/IDidMount
(did-mount [this]
(om/set-state! owner :mounted true))
om/IRenderState
(render-state [_ state]
(html
(if (om/get-state owner :mounted)
[:div "COMPONENT ONE"]
[:div "STILL WAITING TO MOUNT"])))))
(defn component-two [data owner opts]
(reify
om/IRenderState
(render-state [_ state]
(html
[:div "COMPONENT TWO"]))))
(defn tabs [data owner opts]
(reify
om/IInitState
(init-state [_]
{:active-tab :c-one})
om/IRenderState
(render-state [_ state]
(html
[:div
[:div
[:a {:href "#" :onClick (fn [e] (om/set-state! owner :active-tab :c-one))} "COMPONENT ONE"]
[:a {:href "#" :onClick (fn [e] (om/set-state! owner :active-tab :c-two))} "COMPONENT TWO"]]
(println (om/get-state owner :active-tab))
(case (om/get-state owner :active-tab)
:c-one (om/build component-one data)
:c-two (om/build component-two data))]))))
(defn app-view [data owner]
(reify
om/IRenderState
(render-state [_ state]
(html [:div
(om/build tabs data )]))))
(om/root app-view {} {
:target (gdom/getElement "app")})
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment