Fork me on GitHub
#clojurescript
<
2020-01-19
>
carocad14:01:59

hey everyone, I am having a problem with the Closure compiler and I am not sure if this is a bug or not. If I pass a node.js library through it the output code is no longer valid (i.e. with nodejs target it removes certain symbols which are required so it complains about it being undefined later on). However if I use webpack to bundle it into a single js file and then give it to the Closure compiler it works properly (with browser target). Is this a bug in the node.js parsing ? should I report it or am I doing something wrong :thinking_face: ?

knubie15:01:50

@U0LJU20SJ You can try changing the :optimizations level to :simple

carocad18:01:35

I didnt even set an optimization level and from what I see in the documentation it defaults to :none which is why I am wondering about it

awb9916:01:14

I have a clojurescript project that pretty much defines Interfaces only. But then I have one function (defn add-renderer [kw func] ...) that is used by other projects in order to add renderers to the application. Now my Problem is that the implementation of add-renderer brings along all kind of dependencies. So I would like to implement that function in the main application and in the interface project just define it via (define add-renderer). Is this possible? I guess I cannot override the namespace to add the implementation. Any ideas?

enforser17:01:00

How are the main and interface projects communicating with another? Is the interface one a library being used by the main one?

awb9917:01:32

So basically I have a Notebook app that renders Notebooks

awb9917:01:56

Then I have the Renderable project which defines the Interfaces and this function

awb9917:01:21

And then I have UI Plugin projects that define tenderers that only reference Renderable

awb9917:01:05

1. Renderable: (interfaces and add-renderer) has no dependencies

awb9917:01:29

2. UI Plugin: refer to Renderable

awb9917:01:52

3. Notebook: refer Renderable and UI Plugin

awb9917:01:07

I also have a Dynamic clojurescript bundler, so if this idea works then I will have to change structure to:

awb9917:01:11

1. Renderable

awb9917:01:21

2. RenderableImpl

awb9917:01:27

3. UI Plugin

awb9917:01:32

4. Notebook

enforser17:01:01

You could make add-interface dynamic and define it with your actual implementation from the main application. https://lambdaisland.com/blog/2019-12-09-advent-of-parens-9-dynamic-vars-clojurescript I think it'd look something like this:

;; make dynamic var in interface library
(def ^:dynamic *add-interface* (fn [& _] (prn "Oops! Must overwrite add-interface")))

;; in other parts of project

(defn add-interface [] (prn "rebound"))

(binding [*add-interface* add-interface]
  (*add-interface*)) ;; prints 'rebound'

(*add-interface*) ;; prints "Oops!..."

enforser17:01:31

if you weren't in Clojurescript I'd suggest taking a look at https://clojuredocs.org/clojure.core/intern however, I don't think the equivalent function is in cljs.

enforser17:01:49

I think the cleanest solution could be to avoid re-binding vars, and just pass the add-renderer function into your library as an argument.

(defn my-add-renderer [] ...)

(interface.lib/some-function my-add-renderer ...)

awb9919:01:29

I like your last idea! I just have to figure out a way to determine when a library was loaded. Basically the UI Plugins register Keyword / function combinations that extended normal hickup Syntax. Currently they do so in the project itself. So if I change the interface to (available-renderers kw func) then this could be called by the Notebook.

awb9920:01:18

The first approach I don't think will work.. because the rebinding appears not to be available globally.. and my UI Plugins need to call the register function directly. So I guess they always see the mock implementation

clslcl22:01:35

If anybody might find it useful https://github.com/stacksideflow/cljs-yagni, basically dead code finder for cljs I put together last week. Pretty much in testing stage, got some good results on larger codebases. Would appreciate feedback shall you give it a try on your project!