Fork me on GitHub
#clojurescript
<
2017-04-04
>
kriss06:04:53

I need help Why my while in scss don't work ?

$types: 1
$margin: 40px

@while $types < 5
.block#{$types}
margin-left: $margin + 20
$types: $types + 1
I need loop to create . Please help
.block1 {
  margin-left: 40px
}.block2 {
  margin-left: 60px
}.block3 {
  margin-left: 80px
}.block4 {
  margin-left: 100px
}.block5 {
  margin-left: 120px
}

witek10:04:20

How to load a namespace in ClojureScript? I have a String (def s "my.name.core"). Now I want to load this namespace. In Clojure (require s) works. But in ClojureScript I get an error: Arguments to require must be quoted. Offending spec. Any suggestions?

thheller10:04:43

@witek can't do that dynamically in clojurescript

darwin11:04:50

for dynamic require I would look into goog.require

witek11:04:28

What do you mean by goog.require? Could you please point me API docs or something? Thank you.

thheller11:04:44

please do not use goog.require dynamically, do not use at all even

darwin11:04:09

ah, ok, I thought it is the way how to load clojurescript compiler modules

thheller11:04:11

@witek why do you want require?

thheller11:04:26

@darwin in a way yes .. but it is very different from require and cannot be done dynamically in optimized builds. it works only in :none

witek11:04:47

I have a multimethod which dispatches on a keyword. And I have a lot of keywords. Now, the defmethods are all in different namespaces. But the namespaces can be derived from the keyword. Therefor I need to load all these namespaces.

thheller11:04:26

can't do that in CLJS because of the way :advanced optimizations work

witek11:04:49

Even macros can't do this?

witek11:04:30

So I need some hook into the build process which would produce the required code, right?

thheller11:04:08

no, just create a namespace which just has a :require for all the namespaces

thheller11:04:14

and then require that namespace somewhere

thheller11:04:32

ie. in your main app entry namespace (or just put the requires there)

witek11:04:14

That is exactly what I was trying to avoid at first. 😞

thheller11:04:36

well that is a lot less work than hooking into the build process

witek11:04:16

I will create a edn file with all my keywords and then write a code generator which generates a cljs which contains the requires and defines all my keys. That should work. Ugly...

thheller11:04:59

so you write all namespaces into that file then generate a bunch of code

thheller11:04:19

instead of writing the namespaces directly into a :require?

witek11:04:46

Yes. Because it is not a one thime thing. I have multiple uses of this pattern.

robert-stuttaford11:04:45

@anmonteiro still tracking that async bug, i see that closurelib hasn’t released yet — is there a good place to track where they plan releases?

rauh12:04:16

@witek It's not a great idea but you can write a macro that emits the goog/require calls instead of generating cljs code

torbjornvatn12:04:01

has anyone been able to use cljs.spec in any useful manner? When I try to use it for a simple test with stest/check I get

[{:spec #object[cljs.spec.t_cljs$spec11762], :clojure.test.check/ret {:result #object[Error Error: Unable to construct gen at: [] for: [object Object]]}, :sym graphiti-trigger.core/generate-job-name, :failure #object[Error Error: Unable to construct gen at: [] for: [object Object]]}]
back

torbjornvatn12:04:46

I guess it has something to do with this issue http://dev.clojure.org/jira/browse/CLJS-1792

sb13:04:54

Hi, if I have compojure/hiccup site and I would like to use after login the user data (friend/monger) at the reagent side like az “app” div integration, how to possible to do? I can put reagent application in the div etc.. but how to get data from clj side? Is that possible? (sorry for the beginner question)

sb13:04:56

I would like to get the active logged in user id.

danielgrosse13:04:52

I create a partial with (def foo (partial bar @bla)) but @bla is set later. When I call the partial, the passed argument is null. How could I assure that the set atom is used?

mrchance13:04:45

@danielgrosse make bla dereference it

mrchance13:04:33

Your solution would require a macro to prevent evaluating @bla when foo is defined

moxaj13:04:32

@danielgrosse try (def foo (fn [& args] (apply bar @bla args)))

moxaj13:04:07

or is there any specific reason you need to use partial?

danielgrosse13:04:06

@moxaj no, i wanted to shorten a function call for convinience

juhoteperi14:04:11

lib-path here https://github.com/clojure/clojurescript/blob/master/src/main/clojure/cljs/closure.clj#L1525 is the ""app/js/dependencies/google-blockly" so else branch in both if is used

juhoteperi15:04:45

I tested this with figwheel-template project + (:require [Blockly.Blocks]) + :libs ["blockly-master"] and this works for me

juhoteperi15:04:58

It is possible there is a bug with path handling in Windows

juhoteperi14:04:52

@mrdalloca Doesn't the exception contain stacktrace with file names and line numbers?

mhuebert14:04:24

is it a problem to set the cljs compiler :language-in option to :ecmascript5? (to use .catch without the Keywords and reserved words warning)

Tiago Dall'Oca14:04:25

Not at all. I've just tried that and the exception remains. Thanks for the reply!

deg14:04:52

(cross-posting from #beginners; no response there) What is a simple lein template for a CLJS library project? Details: I have widgets and utility code that I've built on top of re-com for various projects. I'd like to centralize them for reuse. So, I want to move them into their own project. - This project will never run standalone, so I don't need any server component - I want a simple project.clj script that doesn't try to do too much (at least not yet!). I looked at re-com's project.clj but, at 172 lines, it is doing far more than I want to bite off right now. - This code is still evolving, so I'd like to be able to edit it live. Typically, I'll be working on it from within the context of a project using it. So, I don't think this library needs to run figwheel, right? It's code just needs to be visible to the figwheel magic in the client project. - I do want to be able to run standalone tests on this library code, without involving any client project.

anmonteiro14:04:00

@robert-stuttaford I've been tracking that too. I thought they would have released something by now

anmonteiro14:04:18

I don't know any other place than the GH repo + mailing list

anmonteiro14:04:24

I'm following both

robert-stuttaford14:04:04

ok, i guess i’ll go back to Strategy Alpha: Wait A While ™

anmonteiro14:04:58

@robert-stuttaford tbh I'm glad they haven't released yet, I'm hoping this makes it in https://github.com/google/closure-compiler/pull/2343

robert-stuttaford14:04:36

how does it help us Cljsers?

fearphage19:04:45

I'm trying to track down a fix. So this fix http://dev.clojure.org/jira/browse/CLJS-1931 led to this bug https://github.com/google/closure-compiler/issues/2336 which I believe is fixed in clojurescript 1.9.495. I upgraded clojure, clojurescript, and lein-cljsbuild to the latest. However when I build, I'm still getting the same error from before the fix -- No newline allowed before '=>'. I don't know how to move beyond this point. Any help would be appreciated.

jr19:04:16

@fearphage that bug exists in the latest cljs release

gklijs19:04:37

@fearphage I just reverted the cljs dependency to the version I used before, after I updated al to latest, and ran into this error..

anmonteiro19:04:19

@fearphage your conclusion is wrong. This is the ticket that led to the bug: http://dev.clojure.org/jira/browse/CLJS-1952

anmonteiro19:04:48

It’s not fixed in 1.9.494 (1.9.495 is not an official release, btw, and you shouldn’t be using it)

anmonteiro19:04:01

we’re waiting on the Google Closure Compiler team to bump the version

anmonteiro19:04:11

then we upgrade in CLJS and release a new version

fearphage20:04:13

Is there a path forward now with the cljs fix and some version of the compiler or am I just stuck waiting for the compiler team?

anmonteiro20:04:39

I don’t understand what you mean by “with the cljs fix"

anmonteiro20:04:07

this is Closure Compiler problem, and until it’s fixed upstream you need to use CLJS 1.9.473 or below

fearphage20:04:06

which I just noticed is tagged with 1.9.495

fearphage20:04:25

Maybe I'm confused. I thought I would be able to get that fix somehow without the async bug. I don't believe that is the case.

dnolen20:04:32

@fearphage you need to wait for a ClojureScript release that has a dependency on a Closure release that has fixed the bug

fearphage20:04:55

Thank you for the clarification.

anmonteiro20:04:26

@fearphage AFAICT you can use that fix with 1.9.473

john21:04:44

Got a weasel repl connected to a web worker 🙂

noisesmith21:04:06

so is that still using the technique of getting the string of a function and sending it as text?

john22:04:16

@noisesmith I'm going to see how far I can get without using self-hosted

noisesmith22:04:34

oh, cool - I think that's a good choice actually

john22:04:52

Yeah, I figured out how to .call cljs compiled to js with parameters, so as long as the worker is using the same cljsbuild compilation, their names should match up.

john22:04:01

even in advanced compilation mode

john22:04:11

Which is a trick servant uses. It just sends the main.js file you're using for the main thread and passes it to (new js/Worker ...

thheller22:04:08

@john not sure what you are up to, but doing anything dynamic in :advanced is really asking for trouble 😉

john22:04:15

but it apparently does so carefully, because I'm getting all kinds of "document not defined" errors when trying to require in a repl connected to webworker

john22:04:53

Just seeing how far I can get

john22:04:10

servant appears to work in :advanced mode

john22:04:39

I can use standard cljs functions in the webworker, but I can't do any new requiring, as apparently Object.goog.importScript attaches imported scripts to the dom

thheller22:04:19

why do you want to run the REPL in the worker?

john22:04:56

I want to flip the model inside out. Do all "main" work, including the repl, in the worker, and offload to the UI thread only UI updates.

john22:04:11

And run arbitrary code on the UI thread with some macro like (on-ui ...

john22:04:54

And see if I can run parts of Om or Reagent/re-frame on the worker thread

thheller22:04:28

I can see those parts running in the worker

thheller22:04:54

but given that a worker is basically a sandboxed VM that just can't do some things the main thread can do

thheller22:04:16

I'm not sure I see the potential benefit of having the REPL in the worker

john22:04:16

You'd probably have to implement some library that proxies necessary dom interactions and other restricted resources for it to be useful probably

thheller22:04:19

ie. the worker cannot restart itself

john22:04:40

I'm envisioning one master worker, which the main UI thread spawns and monitors. You work on the master thread and spawn subworkers from there.

darwin22:04:51

I would read how react native does that, they had to implement a bridge between JS engine and native platform

john22:04:06

Apparently chrome has a sub-worker bug though

darwin22:04:08

you basically want to do react native between a web worker and main JS context

john22:04:58

Yeah, I've been seeing a lot of web worker bug complaints over on the react-native issue trackers

john22:04:43

@darwin I'll def check them out

john22:04:27

what's a shame is that js/importScripts is available in the WorkerGlobalScope. cljs just wants to use Object.goog.importScripts which instead references the dom, apparently

thheller22:04:54

where do you get Object.goog.importScripts from?

john22:04:12

That's from a repl on the webworker

thheller22:04:31

ah that is not js/importScripts .. it is actually goog.importScripts_ something entirely different

thheller22:04:42

and yes the goog.require stuff expects a DOM

john22:04:53

right, but the webworker context has it's own importScripts

john22:04:05

part of the webworker api

thheller22:04:22

yeah I know but you are not calling that

john22:04:11

do you know if any way I can monkey patch the require/importScript pipeline on the webworker to make it use js/importScript?

thheller22:04:21

ah hehe wait ... you are calling (require 'something) in the REPL .. that calls eval

john22:04:38

which piggieback is probably intercepting

thheller22:04:52

so you need to solve 2 things

thheller22:04:35

but (set! (.-CLOSURE_IMPORT_SCRIPT js/self) (fn [x] (js/importScripts x))) should do it

thheller22:04:42

but only if you call that in the worker

thheller22:04:54

this is in goog/base.js from closure

john22:04:57

that worked

john22:04:59

Well, require works now 🙂

john22:04:08

And now I can ns into other namespaces. Thanks @thheller that info was so clutch!

thheller22:04:37

well you need to solve the second problem still, the main threads still needs to update the code as well

thheller22:04:52

or you will go out of sync

john22:04:10

@thheller so I need to think about this. In what ways do you think their environments can get out of sync? Because both the main thread and the worker thread are using the same compiled main.js.

thheller22:04:59

so I suppose you are going to call React.render(foo) in the main UI thread

thheller22:04:28

you update a view function and ship the update via the REPL

thheller22:04:36

only the worker sees that

thheller22:04:57

main thread will still render using the old stuff

john22:04:09

what "old stuff"

thheller22:04:43

well any code that runs in the UI

john23:04:10

so there's state. I'm creating a new datatype that auto syncs all state changes to workers that have access.

john23:04:07

so If you send a call to the remote thread that references local state, when the remote end calls the state, it will hopefully access the local version of the synced datastructure

john23:04:18

local to the worker

john23:04:51

When a parent worker inits a "shared atom" it populates the downstream environment with a new var corresponding to the one in the parent worker.

thheller23:04:16

treat it like a client->server model, the UI is the server, the worker is the client. you update some code in the client, that code creates some data and sends it to the server

thheller23:04:25

the server blows up since it didn't understand the data

thheller23:04:41

because it didn't get the update

john23:04:08

in the repl, yes. But if your "update" is to the source code, once you reload the page the code is reloaded in both contexts. And how often does static code, when not using a repl, generate new functions?

john23:04:29

I mean, what will React.render(foo) do to the environment, when not at the repl... ah, perhaps anonymous functions / closures?

john23:04:11

You generate an anonymous function at run time. It will have a set of arities not available to the receiving environment, right?

thheller23:04:58

I don't know what you are doing with the REPL

thheller23:04:08

but yes the "reload the page" resets everything

john23:04:56

so a few days ago I was discussing you with you and others this whole idea about putting a repl in a webworker

john23:04:30

what I've got set up at the moment, I don't have a self-hosted repl in the worker.

john23:04:24

I'm just running a (.call ... on the compiled javascript from the forms I ship to the worker.

john23:04:43

So all compiled. Not exactly a repl.

john23:04:33

So I'm trying to figure out how much milage I can get on just that alone, without the self hosted option.

john23:04:42

So in this scenario, dynamicity will be much more constrained than with the other, but you get :advanced compilation

thheller23:04:01

you do not get a REPL in :advanced

thheller23:04:08

that will never work

john23:04:24

right, it's not really a repl, though, right?

john23:04:55

it's a Read js/eval Print loop, per say. And it doesn't loop 🙂

thheller23:04:10

I do not get what you are doing to be honest

thheller23:04:16

can you give an example?

john23:04:06

so, say you define some asynchronous (search-wikipedia ... function. It updates a shared atom sa. You send off that function with (send sa search-wikipedia "cats") and it populates sa ... at some future point, the parent thread will be able to see the results in sa

john23:04:07

because search-wikipedia is defined in both contexts, referring to the sa var in both contexts, the function "just works"

thheller23:04:54

I would do this as (.postMessage my-worker (pr-str {:action :search-wikipedia :query "cats"}))

thheller23:04:08

in the worker read that message

thheller23:04:03

and (do-action msg) with (defmulti do-action :action) (defmethod do-action :search-wikipedia [{:keys [query]}] ...)

thheller23:04:39

how you handle data synchronization is up to you

thheller23:04:58

but also just data back and forth

thheller23:04:24

no need to ship code around and other reflection like hacks

john23:04:20

Yeah, that's a sensible way to use webworkers

thheller23:04:09

I would abstract that on top or core.async channels

thheller23:04:57

so you put a message on a channel and read something off another channel

thheller23:04:25

so the code can work with 0 or more workers

thheller23:04:08

you seem to be fixated on the agent abstraction which is terrible to begin with 😉

john23:04:26

I like the idea of doing a simple (map #(send sa %) (take 10 (cycle [ten-second-job]))) and watch that spin up a pool of four workers. All without any user code required.

john23:04:26

And to send-off and arbitrary function with a simple (send-off sa ... without any extra user code required.

john23:04:43

for long running functions

thheller23:04:33

so define your (defmethod long-running-functions :foo [...]) instead of (defn foo [...])

john23:04:18

wouldn't work for anonymous functions

thheller23:04:18

(send-off sa :search-wikipedia ...)

thheller23:04:52

ah you are still under the impression that this will work for anonymous functions

thheller23:04:59

good luck 😉

john23:04:09

well, I got it to work for simple anonymous functions so far

john23:04:32

I'm not sure what the limit on that simplicity is going to be

thheller23:04:41

(let [x 1] (send-off sa #(+ x 1))

john23:04:00

Uncaught ReferenceError: x is not defined

john23:04:41

can I capture bindings with a macro and feed them into the function?

thheller23:04:24

if things where this simple distributed computing would not be this hard

john23:04:09

well, agents in Clojure seem to implement something called "binding conveyance"

thheller23:04:41

agents in clojure work in the JVM, they can share memory with the caller

thheller23:04:58

UI and a worker can not

thheller23:04:07

so everything needs to be serialized back and forth

thheller23:04:21

that just doesn't work for everything

thheller23:04:07

also binding conveyance is about keeping the dynamic vars that were set when the agent was started ... (I think)

thheller23:04:29

it is definitely not about local bindings though