Liking cljdoc? Tell your friends :D

Pathom Viz Connector

pathom viz connector cljdoc

This library contains the code needed to connect Pathom parsers with the Pathom Viz Electron standalone tool.

Setup

deps.edn

{:deps {com.wsscode/pathom-viz-connector {:mvn/version "RELEASE"}}}

JS deps

When using from Clojurescript, you need to have the websockets dependency:

npm i websocket

Connecting parsers (Pathom 2)

To connect the parser with the electron, follow the example:

(ns my-ns
  (:require [com.wsscode.pathom.viz.ws-connector.core :as p.connector]
            [com.wsscode.pathom.core :as p]
            [com.wsscode.pathom.connect :as pc]))

; you can use goog.defines on ClojureScript or env vars in Clojure
; the important part is to have a flag to decide when to connect the parser
(def CONNECT_PARSER? true)

(def registry
  [(pc/constantly-resolver :works "WORKS!!")])

(def parser
  (cond->> (p/parser
            {::p/env     {::p/reader               [p/map-reader
                                                    pc/reader3
                                                    pc/open-ident-reader
                                                    p/env-placeholder-reader]
                          ::p/placeholder-prefixes #{">"}}
             ::p/mutate  pc/mutate
             ::p/plugins [(pc/connect-plugin {::pc/register registry})
                          p/error-handler-plugin
                          p/trace-plugin]})
    CONNECT_PARSER?
    (p.connector/connect-parser
      {::p.connector/parser-id ::my-parser})))

connect-parser returns a parser that will be have all requests logged into the electron app.

Connecting env (Pathom 3)

For Pathom 3 you must use the namespace com.wsscode.pathom.viz.ws-connector.pathom3.

The setup is similar, you call a function in your env, and from that point all you can communicate with it and track the requests made:

(ns com.wsscode.pathom-viz.connector.demos.pathom3
  (:require [com.wsscode.pathom.viz.ws-connector.core :as pvc]
            [com.wsscode.pathom.viz.ws-connector.pathom3 :as p.connector]
            [com.wsscode.pathom3.connect.built-in.resolvers :as pbir]
            [com.wsscode.pathom3.connect.indexes :as pci]
            [com.wsscode.pathom3.interface.eql :as p.eql]))

; you can use goog.defines on ClojureScript or env vars in Clojure
; the important part is to have a flag to decide when to connect the parser
(def CONNECT_PARSER? true)

(def registry
  [(pbir/constantly-resolver :pi Math/PI)
   (pbir/single-attr-resolver :pi :tau #(* 2 %))])

(def env
  (cond-> (pci/register registry)
    CONNECT_PARSER?
    ; give your environment a unique parser-id, this will ensure reconnects work as
    ; expected
    (p.connector/connect-env {::pvc/parser-id ::env})))

(comment
  (p.eql/process env
    [:tau]))

Render Graph on Logs (Pathom 3)

To log graphs in the Pathom Viz you can use the helper from com.wsscode.pathom.viz.ws-connector.pathom3.log-view

Here is one example:

(ns com.wsscode.pathom-viz.connector.demos.pathom3-log-graph
  (:require [com.wsscode.pathom.viz.ws-connector.pathom3.log-view :as log-v]
            [com.wsscode.pathom3.connect.built-in.resolvers :as pbir]
            [com.wsscode.pathom3.connect.indexes :as pci]
            [com.wsscode.pathom3.interface.eql :as p.eql]))

(def registry
  [(pbir/constantly-resolver :pi Math/PI)
   (pbir/single-attr-resolver :pi :tau #(* 2 %))])

(def env
  (pci/register registry))

(comment
  ; logs the graph from the root
  (log-v/log-execution-graph
    (p.eql/process env [:tau])))

Can you improve this documentation?Edit on GitHub

cljdoc is a website building & hosting documentation for Clojure/Script libraries

× close