Skip to content

Commit

Permalink
input watching improved
Browse files Browse the repository at this point in the history
  • Loading branch information
awb99 committed Aug 29, 2023
1 parent 3ed9a97 commit 3e7e09d
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 16 deletions.
40 changes: 28 additions & 12 deletions lib/tradingview/src/ta/tradingview/goldly/algo/interaction.cljs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,9 @@
[ta.tradingview.goldly.interact2 :as i]
))

(defn on-load-finished [& args]
(println "on-load-finished: " args))

(defn symbol-changed? [old-value new-value]
(let [old (get-in old-value [:opts :symbol])
new (get-in new-value [:opts :symbol])]
Expand All @@ -12,16 +15,31 @@
false
true)))

(defn on-load-finished [& args]
(println "on-load-finished: " args)
)
(defn algo-changed? [old-value new-value]
(let [old (get-in old-value [:algo])
new (get-in new-value [:algo])]
(println "algo old: " old " new: " new)
(if (= old new)
false
true)))

(defn on-symbol-change [algo-ctx tv s]
(println "symbol changed to: " s)
(defn on-input-change [algo-ctx tv old new]
(let [{:keys [algo opts]} (c/get-algo-input algo-ctx)
{:keys [symbol frequency]} opts]
(c/set-algo-data algo-ctx nil)
(i/set-symbol tv s frequency on-load-finished)
{:keys [symbol frequency]} opts
symbol-changed (symbol-changed? old new)
algo-changed (algo-changed? old new)
]
(when symbol-changed
(println "symbol changed to: " symbol))
(when algo-changed
(println "algo changed to: " algo))

(when (or symbol-changed algo-changed)
(println "resetting algo-ctx data..")
(c/set-algo-data algo-ctx nil)
(println "switching tv symbol..")
(i/set-symbol tv symbol frequency on-load-finished))

nil))

(defn track-interactions [algo-ctx tv]
Expand All @@ -30,7 +48,5 @@
(add-watch input :algo-input
(fn [key state old-value new-value]
(println "algo-ctx input changed to:" new-value)
(when (symbol-changed? old-value new-value)
(on-symbol-change algo-ctx tv (get-in new-value [:opts :symbol])))

))))
(on-input-change algo-ctx tv old-value new-value))
)))
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@
:options {:autosize true
:symbol symbol}})]
(reset! tv widget)
(i/track-interactions algo-ctx @tv)
(i/track-interactions algo-ctx widget)
(.onChartReady @tv #(println "TradingView ChartWidget has loaded!"))))
:component-will-unmount (fn [this]
(println "TradingViewChart.ComponentDid-UN-Mount")
Expand Down
6 changes: 3 additions & 3 deletions lib/tradingview/src/ta/tradingview/goldly/interact2.cljs
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,6 @@
;(println "tv set symbol:" symbol "interval: " interval)
(set-symbol tv symbol interval on-data-loaded))
([tv symbol interval on-load-finished]
;(println "tv set symbol:" symbol "interval: " interval)
(.setSymbol tv symbol interval on-load-finished)
nil))
(println "tv set symbol:" symbol "interval: " interval)
(.setSymbol tv symbol interval on-load-finished)
nil))

0 comments on commit 3e7e09d

Please sign in to comment.