Fork me on GitHub
#cljsjs
<
2017-08-29
>
rovanion18:08:56

So say I want to use fabric through cljsjs. I've put [cljsjs/fabric "1.5.0-1"] in the dependencies vector of project.clj. But after restarting leiningen/figwheel I'm told that "there's no such namespace cljsjs/fabric" when running (ns fab-test.core (:require cljsjs/fabric)). What am I doing wrong?

juhoteperi18:08:22

@rovanion The foreign-lib ("namespace") names don't use /, the correct name is cljsjs.fabric

rovanion19:08:10

Sorry, that was a pretty obvious typo. But I'm back to the error message I had previously today: That cljsjs is not defined.

rovanion19:08:02

Though it is loaded into the browser, I can access fabric.Canvas in the console and js/fabric.Canvas in cljs.

rovanion19:08:49

(ns fab5.core                                                        
    (:require [cljsjs.fabric :as fab]))

(prn js/fabric.Canvas) ; => #object[klass]                           
(prn fab/Canvas)       ; => #object[ReferenceError ReferenceError: cljsjs is not defined]

juhoteperi19:08:33

@rovanion Fabric package doesn't support :global-exports so you can't use :as alias with it, you need to access it through the global

juhoteperi19:08:44

If you want, you could add

{:file "cljsjs/fabric/development/fabric.inc.js",
   :provides ["cljsjs.fabric"],
   :global-exports {cljsjs.fabric Fabric}
   :file-min "cljsjs/fabric/production/fabric.min.inc.js"}
To :foreign-libs in compiler-options to use global-exports (remember to quote symbols in global-exports depending where you set this)

juhoteperi19:08:44

Reagent changelog and alpha upgrade guide might be the best resources related to this, for now: https://github.com/reagent-project/reagent/blob/master/docs/0.8-upgrade.md

rovanion19:08:14

In my project.clj or (based on some googling) in a src/deps.cljs file in the cljsjs package?

juhoteperi19:08:50

you can overwrite the deps.cljs options from cljsjs packages, in your own cljs compiler-options, e.g. in your project.clj, when using lein

juhoteperi19:08:30

Though you can use global-exports like this, it might be best to just use the old way (access through the global object) until the new features are ironed out 🙂

rovanion19:08:37

Right, this seems a bit complex for just playing around.