This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
2016-12-31
Channels
- # beginners (57)
- # boot (25)
- # cider (86)
- # cljs-dev (6)
- # clojure (137)
- # clojure-russia (7)
- # clojure-spec (10)
- # clojure-turkiye (1)
- # clojure-uk (47)
- # clojurescript (37)
- # cursive (10)
- # datascript (2)
- # datomic (2)
- # dirac (59)
- # emacs (1)
- # hoplon (46)
- # instaparse (122)
- # om (32)
- # om-next (1)
- # onyx (3)
- # pedestal (2)
- # perun (4)
- # protorepl (6)
- # re-frame (15)
- # reagent (60)
- # rum (4)
- # specter (7)
- # sql (3)
- # untangled (3)
- # yada (4)
Hi. Am trying to use https://github.com/ariutta/svg-pan-zoom in a reagent application. It works correctly, until I turn on optimizations. I have created an externs file including the library's sole function: function svgPanZoom() {};
I tried setting those callbacks in the :component-did-mount
lifecycle part, e.g. :
:component-did-mount
(fn []
(.setOnZoom @pan-zoom (fn [level]
(reset! zoom-level (cond (< level 4) "wide"
(< level 10) "mid"
:default "narrow"))))
;...
@polymeris do you mind showing the rest of the component so i can try and replicate?
My first inclination would be to think there is something missing in the externs file. I haven't needed to export an inner anonymous function before, but first times for everything.
here is an example: https://github.com/reagent-project/reagent-cookbook/blob/426442dea91f33a6f2a91c39586767e33d68a7ad/recipes/bootstrap-datepicker/externs.js
do you have an example of an externs file that specifies the methods of an object returned by another function?
hmm, these might be helpful: https://github.com/reagent-project/reagent-cookbook/blob/426442dea91f33a6f2a91c39586767e33d68a7ad/recipes/leaflet/externs.js https://github.com/reagent-project/reagent-cookbook/blob/426442dea91f33a6f2a91c39586767e33d68a7ad/recipes/google-maps/externs.js
in the leaflet example, for instance, there is an L.map
object, with a setView
function... but in my case I don't have a name for the object svgPanZoom(...)
returns
Admittedly I'd be resorting to "try something and see if it works" which is definitely not helpful lol š Hopefully someone else can chime in that is better at externs than I am
I tend to resort to looking thru cljsjs (for example https://github.com/cljsjs/packages/blob/master/chance/resources/cljsjs/common/chance.ext.js) and their respective libraries and blindly try to pattern match ...
I don't even grok the whole prototype thing -- am doing CLJS because I wanted to avoid JS š
I can only offer this: https://github.com/clojure/clojurescript/wiki/Compiler-Options#pseudo-names
(I'm not sure if it has already been used?)
@mikethompson nice tip, haven't seen that before!
Combine it with https://github.com/clojure/clojurescript/wiki/Compiler-Options#pretty-print true
:pseudo-names true
:pretty-print true
That will help a lot
Yeah. there are a lot of options. Also will try setting :closure-warnings {:externs-validation :warning}
, whatever that means
The two above will make it pretty clear, pretty fast, where your problem is
The :pretty-print
will also help to contexualize the source of the exception (I assume you are getting an exception), which may add further information.
š got it to work! thanks, @gadfly361 and @mikethompson
var svgPanZoom = function() {
return {'getSizes': function() {
return {'x': 0,
'y': 0,
'viewBox': {'x': 0, 'y': 0, 'width': 0, 'height': 0},
'realZoom': 0}
}};
};
Excellent
onward
Hello, I have a question. I use goog.events to handle browser events. When I register a handler for the mouse_up event and change the state of an atom inside this handler, the components will not be rerendered immediately. In the repl I see that the value of the atom is already changed. Only when I do an interaction the view will be updated and the atom takes affect. Is it possible to force reagent to do a check of pending changes? In advance: reagent/flush do it not. Only reagent/force-update-all works, but the performance is horrible and not for production use. Any ideas?
@david_clojurian it's hard to tell. maybe you could provide a minimum example code?
@metametadata OK, I will create some example code. Give me some time please š
a wild suggestion: try using (doall (for
instead of (for
@david_clojurian or start with a simplest [:p (get @state :during)]
component to check that your view tracks state changes on mouse moves.
If it works then gradually enhance the code until the bug starts reproducing (this way you'll pinpoint the cause of the bug).
If it doesn't work then the problem is not in the component code š
also look in the browser console - maybe there are some warnings from React
@metametadata Thanks for the advices. I will try it, but today there is no time for it š
@metametadata Thank you so much! The advice to put (doall before (for solves my problem.
Take a look how simple it is to embed editable reagent components in a blog post with #klipse https://twitter.com/viebel/status/815332417808531457
@gadfly361 Iām waiting for your (interactive) blog post š
@viebel very cool stuff
It would be great to retrofit any good change you needed in Klipse to replumb
, there is a PR open on custom eval that was abandoned but it was a good idea š