Fork me on GitHub
#clojurescript
<
2019-08-09
>
Aklscc01:08:47

Hey, everyone. Is there anyone used the react navigation as a clojurescript format? It's really confused for me to write it, when the react class component used. For example:

class HomeScreen extends React.Component {
  static navigationOptions = {
    title: 'Home',
    headerStyle: {
      backgroundColor: '#f4511e',
    },
    headerTintColor: '#fff',
    headerTitleStyle: {
      fontWeight: 'bold',
    },
  };
  render() {
    return ...
  };
}
I want get some hints about it...

nha01:08:37

is there a way to ^:exportdefault in ClojureScript?

dnolen01:08:16

@nha what would that do?

dnolen01:08:47

existing export isn't about JS modules btw, it about preserving an api through advanced compilation

dnolen01:08:18

@godwin.ko it's really the only proper way - anything else breaks caching if you're not careful

4
4
Godwin Ko03:08:58

not sure if I can insert code that run during compile time and read an edn config in order to get deployment specific environments?

dnolen01:08:17

@nha we don't really support ES6 stuff (from ClojureScript itself), you should just write some JS if you need to do that for JS consumers

nha01:08:27

Something like that you mean? (untested)

(js/Object.defineProperty js/exports
                          "__esModule"
                          #js {
                               :value true
                               }
                          )
(js/goog.exportSymbol "exports.default" make)
Or just writing it in JS with the JS toolchain etc?

nha01:08:09

(yes the idea is to expose a nicer API to JS consumers)

dnolen01:08:10

yes use JS tooling - we have some support for ES6 modules but it's not very active and I don't know how much we've look at the export side of things

nha01:08:44

I was hoping for something else but that’s understandable 🙂 thanks!

dnolen01:08:55

we can't do everything 🙂

😄 8
dnolen01:08:13

honestly the only real interest we've had wrt. ES6, is allowing you to write ES6 libs that are Closure aware so they can be a part of your build

dnolen01:08:29

stuff like Transit falls into this category

nha01:08:32

Completely fair 😄 And that makes a lot of sense for transit.

andy.fingerhut09:08:25

Is there a way in ClojureScript to call a function defined as private, in another namespace, without a warning that it is private? Not a big deal if there isn't -- just curious.

dnolen12:08:37

@andy.fingerhut you should be able to use the var pattern from Clojure

andy.fingerhut13:08:11

Thx. Will give that a try. I guess I assumed it would not work, given difference in Vars in ClojureScript. Should have gone that extra step before asking.

mfikes15:08:19

One small thing to be aware of, if it is critical to you, is the use of a Var causes a little generated code bloat.

J13:08:34

I'm learning clojurescript. Coming from backend compiled language, can someone recommend some readings / approaches on ways to avoid runtime exceptions. Even typos are harder to spot in dynamic languages. Thanks.

Dave13:08:59

In dynamic languages compile time checking can be replaced by runtime testing 🙂. Maybe spec and test.check are what you need? https://clojure.org/guides/spec

nenadalm05:08:57

For me it's combination of (from most used to less): - thinking about all possible valid inputs (with testing them e.g. via repl) - writing tests (often I copy my previous tries from the repl and add a few more cases) - spec + test.check (I don't use it that often, I'd like to use it more) As for detecting typos early, in browser figwheel tells me about many typos during reload (https://figwheel.org/). I use 2 screens - one I am developing at and second where I have opened browser. For node, I have the output hidden, but it also tells you in console when some namespace couldn't be reloaded because of some typo.

J23:08:24

Thanks both. More tests then. Maybe it's a mentality change for me too. I'm using shadow-cljs. I'll also take a look at figwheel.

Dave13:08:49

Perhaps looking at some videos with the title repl driven development might help. What is quite nice is testing in the repl until you are basically happy with a function, then converting some of those repl executions into tests.

👍 4
J01:08:24

thanks, I'll do just on the topic, with real driven dev how is it going to work with "largish" refactoring?

Dave07:08:48

Possibly large refactoring is more difficult to do with a dynamic language. There are a lot of tools with a typed language which will be able to automate renaming, extracting functions, and things like that. As far as I'm aware there are no such tools for clojure to do this.

J12:08:22

thanks for your repy

andy.fingerhut13:08:53

I tried with-redefs attempting to temporarily reassign the value of function into (or perhaps it was some other function in cljs.core), and it seems not to have taken effect. Is this known limitation of ClojureScript with-redefs?

dnolen13:08:40

with-redefs works

andy.fingerhut13:08:56

Hmmm. Let me see if I can repro.

dnolen13:08:01

you should demonstrate something that doesn't work

dnolen13:08:13

@andy.fingerhut oh I know - ClojureScript direct links the standard lib

dnolen13:08:40

with-redefs does work

dnolen13:08:24

but you can't with-redefs any references already in the standard lib

dnolen13:08:40

not w/o recompiling the standard lib w/ that off

andy.fingerhut13:08:41

In the case of the test where I wanted to with-redefs on a function in cljs.core, it was straightforward for me to work around this by calling my own function my-vector instead of vector, and do (def my-vector vector), the code that called my-vector, then with-redefs to temporarily change the definition of my-vector

dnolen13:08:19

the reason is that redefining the standard lib isn't useful for most users

andy.fingerhut13:08:22

So this sounds like a similar kind of direct linking that exists for Clojure, then. Makes sense.

dnolen13:08:29

but having the standard lib be directly linked is

andy.fingerhut13:08:46

This kind of with-redefs does work for Clojure, though, at least for calls from user code to core fns. So perhaps ClojureScript has one extra 'level' of direct links in the user's code?

andy.fingerhut13:08:22

Yeah, just double-checked. The same example in my gist linked above works differently with Clojure/Java, I think because Clojure's direct linking only applies to calls between functions in core, unless you explicitly compile your own code with direct linking enabled, too.

dnolen13:08:19

well it seems to me that should work as long as you're doing this in a REPL

dnolen13:08:27

feel free to open a minor issue in JIRA w/ this example

andy.fingerhut13:08:35

if you think so, I'm happy to do that. Also perfectly content if the resolution is only a caveat in the docs somewhere.

dnolen13:08:11

I mean it should work at the REPL

dnolen13:08:20

just won't work for compiled code

dnolen13:08:30

which is probably why it hasn't come up before

lilactown20:08:53

how does prepl work in CLJS?

lilactown20:08:37

does it actually start an honest-to-goodness socket REPL in the JS process? or does it rely on a socket repl being started in the JVM compiler process and then does something like piggieback?

lilactown20:08:08

(I’ve only seen it used in Node.js as an example)

lilactown20:08:23

and even if most uses is of the latter piggyback style, is there any “native” support for prepl in CLJS where I could bridge it over websockets or some other protocol?

andy.fingerhut21:08:52

I don't know about prepl. I recently started using ClojureScript with a Node-based socket REPL, and did some experiments to note that starting the JVM process does not also create a node process until and unless some TCP client connects to the socket REPL TCP port. Then it fires up a new node process.

andy.fingerhut21:08:17

From that I am inferring that the TCP connection is going to the JVM process, not the node process.

lilactown21:08:29

yeah that makes sense

lilactown21:08:28

I am hoping there’s some sort of prepl machinery in CLJS as well, where I could build a bridge over websockets or browser messaging protocols to do repl-y things

alpox21:08:55

@lilactown Hi there! Just a small shout-out to thank you for hx! It saves me a lot of troubles when working with third-party libraries relying on react hooks 🙂

lilactown22:08:11

You’re welcome! I’m glad you found it useful and that you’re enjoying it

alpox22:08:24

I really do and I feel like I have much less edges to work around than with reagent. The only workaround I see coming is the integration with re-frame but I remember seeing some demo of yours which I can adapt so that should be fine 🙂

lilactown22:08:00

Yeah, the global state management story with the latest React is a bit rough. A nice integration with re-frame would be really cool but atm re-frame brings in reagent with it and is coupled to it in a few places

alpox22:08:58

Its a pity that re-frame didn't decide to de-couple from reagent and make it drop-in

lilactown22:08:37

there are some benefits that re-frame gets by using reagent’s Reaction directly. in an ideal world, the whole RAtom / Reaction would be separate from reagent, the UI lib

alpox22:08:14

Well, I guess for now the adaption of the RAtom to a useState hook should work good enough (I hope). I'll see soon

alpox22:08:30

Too bad we don't live in that ideal world 🙂

lilactown22:08:42

yep. maybe someday ;)

lilactown22:08:39

my use case is that I am building a dev tool that listens to tap> and interacts with the CLJS process directly. atm I’ve built it with a specific protocol over websockets / Chrome APIs for the exact interactions I need with the user’s runtime state, but I am quickly building just another REPL protocol

currentoor22:08:17

how do i check if my code is running is nodejs or a browser? I was thinking (exists? js/window)

alpox22:08:06

@currentoor I'd maybe opt for (and (exists? process) (not (empty? (.-version process))))

alpox22:08:22

Which would yield true for a node environment

currentoor22:08:09

@alpox i think mean (and (exists? js/process) (not (empty? (.-version js/process))))?

alpox22:08:18

Yes, sorry 😄

currentoor22:08:05

and yes i like that better, js/window can be set when someone tries to write compatible code, this is less likely to accidentally get stomped on

alpox22:08:37

Yes I was thinking the same. I remember seeing some node environments where js/window was set