Fork me on GitHub
#clojurescript
<
2018-06-16
>
richiardiandrea01:06:51

Has anybody ever seen this ClojureScript error?

Unable to construct gen at: [:context] for: object?
Error: Unable to construct gen at: [:context] for: object?
    at Object.cljs$spec$alpha$gensub [as gensub] (/home/arichiardi/git/laputa/lambda-cqrs/out/cljs/spec/alpha.cljs:278:14)
    at Object.cljs$spec$alpha$re_gen [as re_gen] (/home/arichiardi/git/laputa/lambda-cqrs/out/cljs/spec/alpha.cljs:1187:32)
    at /home/arichiardi/git/laputa/lambda-cqrs/out/cljs/spec/alpha.cljs:1174:34
    at /home/arichiardi/git/laputa/lambda-cqrs/out/cljs/core.cljs:4691:16
    at cljs.core.map.cljs$core$IFn$_invoke$arity$4 (/home/arichiardi/git/laputa/lambda-cqrs/out/cljs/core.js:17634:3)
    at cljs.core.LazySeq.sval (/home/arichiardi/git/laputa/lambda-cqrs/out/cljs/core.cljs:3394:18)
    at cljs.core.LazySeq.cljs$core$ISeqable$_seq$arity$1 (/home/arichiardi/git/laputa/lambda-cqrs/out/cljs/core.cljs:3384:1)
    at Object.cljs$core$seq [as seq] (/home/arichiardi/git/laputa/lambda-cqrs/out/cljs/core.cljs:1210:25)
    at Object.cljs$core$every_QMARK_ [as every_QMARK_] (/home/arichiardi/git/laputa/lambda-cqrs/out/cljs/core.cljs:4183:10)
    at Object.cljs$spec$alpha$re_gen [as re_gen] (/home/arichiardi/git/laputa/lambda-cqrs/out/cljs/spec/alpha.cljs:1191:30)

richiardiandrea01:06:10

It seems to be coming from this fspec

(s/def :http/callback
  (s/fspec :args (s/cat :context object?
                        :error #(instance? js/Error %)
                        :response object?)))

richiardiandrea01:06:32

I guess I cannot fspec a higher order function that accepts a JS object yet?

Oliver George03:06:36

Thanks for the new CLJS release.

Oliver George03:06:55

Question about extern inference improving. How much should we trust it and what should we watch out for?

dnolen03:06:26

@olivergeorge hrm I guess report stuff that doesn’t work?

dnolen03:06:44

Advanced compilation etc.

Oliver George03:06:21

Fair enough. Thanks David. Is there anywhere that describes how things improved?

roti07:06:39

how do you deal with the browser back button in a SPA?

Oliver George08:06:28

goog.history has helpers

dnolen11:06:59

@olivergeorge hrm not outside of tickets and commit history

mac14:06:01

I am trying to adapt David Nolen's recent article about using webpack with cljs to include the prosemirror package in a small project, but I am having some challenges getting the mapping right. I have provided a gist here https://gist.github.com/maacl/3af5c646e5139b4fc9eacc46f2eb1218 with the relevant files. The output I get is "undefined". It appears from my testing that prosemirror-state is mapped directly to the EditorState object, whereas I would like for prosemirror-state just to be mapped to the prosemirror-state ns and access EditorState using prosemirror-state/EditorState.

dnolen14:06:33

whatever you want you need to make it so in your index.js file

dnolen14:06:51

JavaScript doesn’t have namespaces so there’s no way to magically make this work

dnolen14:06:09

window.PromiseMirrorState = {EditorState: EditorState}; etc.

mac14:06:58

@dnolen Sorry for the confusion, I did not mean to imply that js has nss. If I do above how would then access EditorState from core.cljs?

dnolen14:06:22

promise-mirror-state/EditorState

dnolen14:06:30

you can determine the structure of the library yourself in index.js is all I was trying to say

mac14:06:07

I get Uncaught TypeError: Cannot read property 'EditorState' of undefined - but I can access EditorState from the console via ProseMirrorState.EditorState

dnolen14:06:28

I think this is a red-herring - you have other problems

dnolen14:06:41

:global-exports {foo [X Y]} is meaningless

dnolen14:06:46

and will probably generate broken code

dnolen14:06:47

it must be {provide-name JavaScriptGlobalName}

dnolen15:06:37

I’ve created an issue to validate :global-exports to avoid this kind of misunderstanding https://dev.clojure.org/jira/browse/CLJS-2781

dnolen15:06:55

@mac another thing I recommend is trying to get one import / export to work for now - remove all the other stuff

dnolen15:06:49

if you can’t get that to work then I’ll look at it - it’s minimal enough to show me if there’s an issue

mac15:06:10

@dnolen Ok, reducing to one import and testing again.

mac15:06:36

@dnolen Ok I updated the gist to reflect the current code, that still produces the same result.

dnolen15:06:20

@mac your gist is lacking in sufficient information to reproduce 🙂

dnolen15:06:24

what packages do I need to install?

dnolen15:06:35

yarn add prosemirror is what I did

dnolen15:06:50

but yarn webpack fails for me

mac15:06:29

@dnolen Sorry did not consider that. You need to do yarn add prosemirror-state

mac15:06:54

@dnolen Other than that the steps are identical to your article.

dnolen15:06:09

@mac it works for me

dnolen15:06:25

I see EditorState logged in the JS console

mac15:06:14

@dnolen I get a warning re using production mode when doing yarn webpack. Can that be the culprit?

dnolen15:06:32

Nope expected

dnolen15:06:44

I really don’t see how this can’t work

mac15:06:06

@dnolen This is very strange. I thought I might be missing a "-" somewhere or something silly like that. My current error is "Uncaught TypeError: Cannot read property 'EditorState' of undefined at core.cljs:4"

dnolen15:06:00

yeah I really don’t know, I can’t reproduce your problem

dnolen15:06:08

there’s literally nothing different from what you are doing and what the guide covers

dnolen15:06:21

and I can’t make it fail the way you are describing

dnolen15:06:47

@mac I’m assuming you deleted out and tried a fresh build just in case?

mac15:06:06

@dnolen I did not, but I did now and that fixed the problem. Sorry, I had no I idea that deleting out was necessary.

dnolen15:06:19

it’s not necessary

dnolen15:06:41

but back when you had the bad :global-exports maybe that messed stuff up

dnolen15:06:54

definitely would trigger bad code gen

mac15:06:58

@dnolen Ah, got it. And I see now, how to achieve what I wanted using index.js. Thanks a lot.

mikerod17:06:41

It sounds like a common cause for problems is just forgetting to clear out old bad state when getting this stuff working.

dnolen17:06:38

well in this case we need to validate since :global-exports leads to code gen and bad input will produce bad output

dnolen17:06:51

and re-running compile won’t fix it because nothing in your own sources changed

mikerod17:06:52

Yeah. Just almost think a FAQ could suggest cleaning old build artifacts as a troubleshooting step. Hah. Then again that may be just a common step for many build related things.

souenzzo19:06:11

How to require libs like material-ui on clojurescript? I added "@material-ui/core" "1.2.1" in my :npm-deps But I dont know how to require. (on js doc is: import Button from '@material-ui/core/Button'; ) When I try ["@material-ui/core/Button" :as button] I get Error: Undefined nameToPath for _CIRCA_material_ui.core.Button on browser (but no error/warning on build)

dnolen19:06:42

scoped modules don’t work with :npm-deps due to a bug in Google Closure

dnolen19:06:47

I have a PR outstanding for that

souenzzo19:06:09

It's a closure regression? On older versions of cljs/closure compiler may work?

dnolen19:06:25

it doesn’t have that particular bug but no idea if it will work

dnolen19:06:55

@souenzzo you’re probably better served by a different approach anyway see https://clojurescript.org/guides/webpack

👍 4
souenzzo20:06:49

Now working! But some doubts: On this setting

{:file           "dist/index_bundle.js"
 :provides       ["react" "react-dom" "button"]
 :global-exports {react     React
                  button    Button
                  react-dom ReactDOM}}
1- provides is about the package name? It should match with some other name? 2- global-exports is a map from "what I require in cljs" to "the name inside window"?

dnolen20:06:15

@souenzzo :provides is the name(s) you want to require

dnolen20:06:35

:global-export is a map from provide to the global JS variable assigned to the library

👍 4
dnolen20:06:47

I think you got it

souenzzo00:06:00

webpack method is just awesome! Now it's way easier to add npm deps But on this method, there is SOME dead code elimitation?

bhauman20:06:27

when you are setting a project up it is often helpful to just include a clean step while you are iterating your configuration i.e. rm -rf out; clj -m cljs.main -c example.core

👍 4
souenzzo20:06:49

Now working! But some doubts: On this setting

{:file           "dist/index_bundle.js"
 :provides       ["react" "react-dom" "button"]
 :global-exports {react     React
                  button    Button
                  react-dom ReactDOM}}
1- provides is about the package name? It should match with some other name? 2- global-exports is a map from "what I require in cljs" to "the name inside window"?

lilactown21:06:15

is it possible to rebind value of a var (e.g. clojure.core/deref), but only for the immediate syntactic scope? e.g. I want to capture deref inside of a function body, but not within any functions called inside of the body

mfikes21:06:47

@lilactown Maybe you could let a local to shadow clojure.core/deref

(let [deref (fn [_] ,,,)] (deref 1) ,,,)

lilactown21:06:23

hmm I tried that and i thought it didn’t work. I’ll try again

lilactown21:06:03

the problem is that I’d like to be able to use @ which expands to clojure.core/deref… fully qualified

lilactown21:06:16

so it’s not using my local shadow

mfikes21:06:46

Right, I think you'd have to explicitly use deref.