I want to use Closure because it is included out-of-the-box with ClojureScript. The trouble is, Closure does not seem to be readily compliant with the React concept of a Virtual DOM, and so typically works by decorating/creating non-virtual DOM items itself. This is causing me grief with data binding. I am trying to use goog autocomplete with data received by ajax api call. After the API call the data is put into my front-end database (I’m using reframe), and I need the goog autocomplete to use that data once it comes in. Whenever Figwheel reloads after initial rendering the AC works; but clearly this isn’t an option for production deployment.
I’ve tried making the item into a form-3 Reagent component, but still the item isn’t properly sensitive to the subscribed data updates. Has anyone figured this out before? Here is what I have now (which works after figwheel reload, but not just after data subscription reload)
(defn dummy-ac
"Trying to make this more reagent compatible by creating the thing ourself.
Consulting https://github.com/google/closure-library/blob/34fcddbda216bb338b2e631b988eb52ed4fdf025/closure/goog/ui/ac/ac.js#L31"
[]
(let [display-key :state-name
data (->> @(rfc/subscribe [:get-us-states]) (map display-key) (apply array))
matcher (goog.ui.ac.ArrayMatcher. data)
renderer (goog.ui.ac.Renderer.)
input-handler (goog.ui.ac.InputHandler. nil nil nil)
auto-complete (goog.ui.ac.AutoComplete. matcher renderer input-handler)
_attach-ac (.attachAutoComplete input-handler auto-complete)]
(r/create-class
{:display-name "dummy-ac"
:reagent-render
(fn []
[:input {:id "DUMMY" :default-value "Dummy States"}])
:component-did-mount (fn [this]
(js/console.log "Mounted this:" (dom/dom-node this))
(.attachInputs input-handler (dom/dom-node this)))})))