(ns clojure-experiments.portal
  ""
  (:require [portal.api :as p]))




;; 
(comment

  ;; This opens a standalone chrome app window
  ;; You can inspect it (right click -> Inspect) to see the URL, etc.
  ;; - we also open this window in `user` ns
  by saving it in a var we can use it from the REPL #portal-atom
  you can use the Electron version - run /Applications / portal.app first !
  (def portal (p/open {:launcher :electron
                       :window-title "something new"}))

  ;; what about :emacs!
  ;; #xwidget-webkit-embed
  ;; You need a build of emacs with Embedded-WebKit-Widgets -WebKit-Widgets.html
  ;; - cool but unusable (no keyboard shortcuts working :( )
  (def portal (p/open {:launcher :emacs
                       :window-title "emacs!?"}))


  (add-tap #'p/submit)

  ;; explore data
  (tap> :hello)
  (tap> [1 2 3])
  (tap> {:x 0 :y 0})

  ;; list of maps can be rendered as tables
  (tap> [{:color :blue} {:color :red}])

  you can event use cider - inspect to inspect @portal !
  (prn @portal)

  ;; you can clear the inspector any time
  (p/clear)

  ;; shutdown
  (remove-tap #'p/submit)
  (p/close)


  ;; you can register your own commands too!
  (p/register! #'reverse)
  ,)

;;; visual-tools-experiments: -tools-meeting-2-summary-video/8674
;;; -> -tools-experiments/tree/main/portal-nrepl



;;; [LA] Meetup: Collaborative Learning - Portal
  
(comment

  (tap> (all-ns))

  ;; timestamps - don't have a nice viewer (yet?)
  (tap> (java.time.Instant/ofEpochMilli (System/currentTimeMillis)))

  ;; if you tap vars, then goto-definition command in portal works
  (tap> #'p/submit)

,)


  Visualize graphs with portal : #L113
(def bar-chart
  ^{:portal.viewer/default :portal.viewer/vega-lite}
  {:data
   {:values
    [{:a "A", :b 28}
     {:a "B", :b 55}
     {:a "C", :b 43}
     {:a "D", :b 91}
     {:a "E", :b 81}
     {:a "F", :b 53}]}
   :mark "bar"
   :encoding
   {:x
    {:field "a"
     :type "nominal"
     :axis {:labelAngle 0}}
    :y {:field "b", :type "quantitative"}}})
(tap> bar-chart)


 
 This opens a standalone chrome app window
 You can inspect it (right click -> Inspect) to see the URL, etc.
 - we also open this window in `user` ns
 what about :emacs!
 #xwidget-webkit-embed
 You need a build of emacs with Embedded-WebKit-Widgets -WebKit-Widgets.html
 - cool but unusable (no keyboard shortcuts working :( )
 explore data
 list of maps can be rendered as tables
 you can clear the inspector any time
 shutdown
 you can register your own commands too!
 visual-tools-experiments: -tools-meeting-2-summary-video/8674
 -> -tools-experiments/tree/main/portal-nrepl
 [LA] Meetup: Collaborative Learning - Portal
 timestamps - don't have a nice viewer (yet?)
 if you tap vars, then goto-definition command in portal works
(ns clojure-experiments.portal
  ""
  (:require [portal.api :as p]))




(comment

  by saving it in a var we can use it from the REPL #portal-atom
  you can use the Electron version - run /Applications / portal.app first !
  (def portal (p/open {:launcher :electron
                       :window-title "something new"}))

  (def portal (p/open {:launcher :emacs
                       :window-title "emacs!?"}))


  (add-tap #'p/submit)

  (tap> :hello)
  (tap> [1 2 3])
  (tap> {:x 0 :y 0})

  (tap> [{:color :blue} {:color :red}])

  you can event use cider - inspect to inspect @portal !
  (prn @portal)

  (p/clear)

  (remove-tap #'p/submit)
  (p/close)


  (p/register! #'reverse)
  ,)




  
(comment

  (tap> (all-ns))

  (tap> (java.time.Instant/ofEpochMilli (System/currentTimeMillis)))

  (tap> #'p/submit)

,)


  Visualize graphs with portal : #L113
(def bar-chart
  ^{:portal.viewer/default :portal.viewer/vega-lite}
  {:data
   {:values
    [{:a "A", :b 28}
     {:a "B", :b 55}
     {:a "C", :b 43}
     {:a "D", :b 91}
     {:a "E", :b 81}
     {:a "F", :b 53}]}
   :mark "bar"
   :encoding
   {:x
    {:field "a"
     :type "nominal"
     :axis {:labelAngle 0}}
    :y {:field "b", :type "quantitative"}}})
(tap> bar-chart)

