Fork me on GitHub
#clojurescript
<
2017-04-17
>
qqq03:04:35

can a single SPA open up two browser windows?

qqq03:04:41

when I look at window.open, I have to feed it a new URL

qqq03:04:52

but I want one "cljs code base" to control both windows, without having to route stuff through the server

akiroz09:04:55

@qqq I'm pretty sure you can have shared web workers in the browser across windows

qqq09:04:28

@akiroz: hmm, is it possible ot treat another window just like a "div" ?

qqq09:04:32

where I an inject stuff into it?

qqq09:04:45

basically I want two windows, one for my SPA, another for pretty printing debug log info during dev time

akiroz09:04:19

You can only communicate between JS processes via message passing but IIRC there's a something along the lines of window.parent if you open a child window...

akiroz09:04:02

browsers usually block pop-ups by default but if it's for development, you might be able to get away with spawning your SPA in the debug window and writing the the debug window using parent.querySelector('#log').value += 'log entry'

qqq09:04:35

@akiroz: actually, by "write", I need to dump formatted DOM elements (like entire tables)

qqq09:04:45

by 'debug window' are you referring to the console where I can only dump text?

akiroz09:04:19

Uh... I'm referring to 2 browser windows

qqq10:04:43

@akiroz: ah, in the "debug browser window" (not devtools), there is a div called "#log" then you select it ... hmmm intersting

qqq10:04:06

so child can modify parent, but parent can't modify child?

qqq10:04:15

so the "SPA" is in the child window, the parent window is the "debug/log window"

thheller10:04:38

@qqq check out the goog.debug namespaces from the closure library, they do have this "debug window" you are looking for

pesterhazy11:04:10

@thheller that's interesting. I tried to get it to work on Klipse but didn't manage

qqq11:04:54

@thheller : thanks! will look into it once I kill this bug first 🙂

souenzzo12:04:01

How to include CSS files from CLJSJS? Example: cljsjs/codemirror has codemirror.min.css file inside the jar, but I cant import this...

madstap13:04:36

@qqq re-frisk also has a debug window thing

mvrc15:04:45

Hello, I'm new to cljs. I have an app, but when i want to build it with :optimizations :advanced, i get the following error : >ERROR: JSC_MISSING_PROVIDE_ERROR. required "pages.calculator" namespace never provided

mvrc15:04:18

Could someone help me please ? Or just explain what i'm doing wrong ? Thanks

darwin15:04:08

@mvrc: go to your cljs build output folder and search for goog.require('pages.calculator'); in generated files

darwin15:04:26

there is probably some code where this is being called without prior goog.provide('pages.calculator') which would offer such module

mvrc15:04:32

Yes, i found it in app/core.js in the folder

darwin15:04:59

ok, so in your app.core namespace, how do you require this pages.calculator?

darwin15:04:03

where does it come from?

mvrc15:04:23

I have in my cljs folder :

mvrc15:04:47

- a folder app with app.core and app.utils

mvrc15:04:03

- a folder pages with all my pages (they all have the same error) and each page is in a subfolder for example calculator is in /pages/calculator/calculator.cljs

mvrc15:04:15

-same thing as above for providers

darwin15:04:52

what is at the top of pages/calculator/calculator.cljs? which goog.provide?

darwin15:04:12

I mean at the top of pages/calculator/calculator.js

darwin15:04:40

isn’t it pages.calculator.calculator?

mvrc15:04:59

no it is pages.calculator. Should i try with pages.calculator.calculator ?

mvrc15:04:26

// Compiled by ClojureScript 1.8.51 {}
goog.provide('pages.calculator');
goog.require('cljs.core');

darwin15:04:00

so for some reason this pages/calculator/calculator.js is not being included before your app/core.js

darwin15:04:33

to me it sounds like some ordering problem of your generated js files

darwin15:04:53

I’ve seen this in :whitespace mode, but never in :advanced

mvrc15:04:28

I've found it thanks to you 🙂

mvrc15:04:43

That was in the naming of the modules

mvrc15:04:19

i should have called them pages.calculator.calculator instead of pages.calculator

darwin15:04:54

ok, so your filesystem names didn’t exactly match your namespace names and clojurescript got confused

mvrc15:04:36

yes, but i thought it was okay because i only get the error in :advanced mode

darwin15:04:59

cannot comment much on that, but I would guess clojurescript expects you to strictly follow the convention without extensive sanity checks, it works in :none mode just by coincidence

qqq16:04:24

I bet https://github.com/binaryage/cljs-oops would ahve solved this problem

darwin16:04:02

@qqq thanks for the plug, but no, it wouldn’t 🙂

qqq16:04:41

@darwin: looks like time for you to write another lib 🙂

darwin16:04:30

he simply didn’t follow naming conventions for namespaces, the behaviour of his compilation output was undefined

benny16:04:06

Instead of posting in the specific channel like #rum or #reagent, I figured this would be the best place for an objective answer, what’s the reason for things like re-frame? Why doesn’t async.core + atoms suffice?

darwin16:04:03

@benny for me the value of re-frame is in their docs/idea, the implementation is nice-to-have, but I would encourage everyone to implement their own

darwin16:04:59

it is not that hard and you then understand full-stack of your app, re-frame is important piece at hart which you should not be afraid to touch / deep debug - but it depends on app of course

benny16:04:36

fair enough, thanks @darwin, I assumed there was no real “restriction” on not using one, but the best practices, “already done for you” piece makes sense

benny16:04:14

mainly wanted to make sure it’s worth it for me to go deeper before I do as I seem to be getting beyond the “surface” and it will just require more learning effort on my part

darwin16:04:31

you are right, there is definitely great value in that quite many people are already familiar with re-frame, so if you use it, you make it easy for them to understand/touch your code

darwin16:04:03

btw. I believe re-frame can be implemented in less than 200 LOC, at least the original concept of v0.5: https://github.com/binaryage/pure-frame/blob/master/src/re_frame/frame.cljs

darwin16:04:18

here is how would you implement the event loop on using core.async: https://github.com/binaryage/pure-frame/blob/master/src/re_frame/v041_router.cljs#L46

darwin16:04:39

but re-frame should not care about core.async or reagent, IMO

john17:04:08

@qqq if you don't mind only having only firefox and chrome compatibility, I believe you can talk between windows using js/BroadcastChannel as well.

mikepence21:04:00

so i am looking at writing cljs wrappers for openseadragon. but i am really at step zero: what does it mean to write cljs wrappers for a JS library that has mutable state? what are the design goals, and what are some easy-to-reason-about examples?

mikethompson21:04:05

@benny > what’s the reason for things like re-frame? Why doesn’t async.core + atoms suffice? re-frame used to use core.async and it still usese ratoms. So you could obviously just use them and build out an alternative solution to re-frame yourself. But then again you could equally ask, why would you even use core.async, you have macros and goog.nexttick, so just build that yourself too. Same with Reagent itself ... why use it? ... just use React and clojurescript. Ultimately, re-frame gives you a leg up around architecture and specifically state managment. If you use it, you won't spend months making lots of subtle design decisions and getting some of them wrong etc. -- even at a pragmatic level there's a reason re-frame stopped using core.async .. you probably don't want to be bothered bumping into problems already solved by someone else. But, having said that, re-frame is about 600 or so lines of code these days. So it is fairly simple.

benny21:04:57

Very true @mikethompson and after investing most of my day digging deeper into re-frame in particular the thought and documentation that comes with it is well worth it

benny21:04:55

"Small" code base or not, the iterations said LOC went through is proven and documented

Aron22:04:04

re-frame docs are so good, i gave them to someone learning react at one point