Fork me on GitHub
#fulcro
<
2018-09-03
>
pauld02:09:17

Hi, I'm going through the development guide and my js console is giving me a

app.intro.js:6 Uncaught ReferenceError: devcards is not defined
    at app.intro.js:6
(anonymous) @ app.intro.js:6

thheller07:09:12

@pauld looks like the fulcro.client.cards may emit devcards related code but doesn't require devcards. try to add a devcards.core require before the fulcro.client.cards require

pauld08:09:34

Ah, thanks! Seems so obvious now that you mention it - works now that I added that require to my intro.cljs file.

levitanong09:09:41

@tony.kay does fulcro 2.6 support DCE for colocated css? :3

thheller14:09:34

is there any support in a defsc for doing stuff in the actual react constructor? ie. I want to construct a function for use as a :ref

thheller07:09:23

(solved without a constructor, also the answer is no there is no way to hook into the constructor)

tony.kay13:09:59

@U05224H0W actually :initLocalState is equivalent to a constructor, other than what it returns becomes the component’s local state.

thheller13:09:00

yes but it is not local state. it is not relevant for render and never changes.

thheller13:09:14

I basically want a component bound function I can use as :ref

thheller13:09:51

not actually using createRef but the principle is the same

tony.kay14:09:40

I use it that way all the time (creating functions for :ref)

tony.kay14:09:00

you can either put the functions in component local state, or put them onto this

tony.kay14:09:57

initLocalState will be called as part of the constructor..the fact that it’s return value has meaning is simple enough: return an empty map if you don’t need CL state

thheller14:09:10

ah right. didn't think to abuse it that way. that works of course.

tony.kay14:09:38

I have considered adding a formal :constructor option to defsc…but other than the documentation value I had considered it overkill because this works already…but I should document that 🙂

tony.kay14:09:42

one or the other

tony.kay14:09:03

make a constructor option or document how you get it

thheller14:09:57

yeah. initLocalState is a bit misleading in the name so I dismissed that when looking through the code.

thheller14:09:28

I opted for a little helper (term-container {:ref (util/ref-fn this ::term attach-terminal)})

tony.kay14:09:38

Yeah. The other thing is a constructor in js land is supposed to call the “super”…and I didn’t want to lead ppl down that path. So I think I’ll stick with it this way and just add docs.

thheller14:09:48

basically only creates the fn once per component

thheller14:09:31

yeah constructor can be misleading as well

thheller14:09:48

but its a pretty typical react pattern to create stuff in the constructor

thheller14:09:55

ie. event handlers, refs, etc

thheller14:09:07

so might be good to have some basic support for that

thheller14:09:22

(apart from initLocalState maybe)

tony.kay14:09:47

I’m going to start by adding it to the docs (doing that now).

tony.kay14:09:37

It’s a borderline case to me: you can get exactly what you want from :initLocalState, so other than the slight misnomer, it doesn’t merit more API.

thheller14:09:53

true but its a rather important aspect to be aware of

tony.kay14:09:43

If you strongly feel a :constructor option is merited, I’m game to add one. I’ve been on the fence about it. I’ve been in the “slim it down” phase for a while 🙂

tony.kay14:09:18

(not that there is anything I can really remove without breakage…but you get the sentiment I’m sure)

thheller14:09:25

looks good. would have answered the question I didn't find an answer for previously

thheller14:09:08

should be ok the way it is. I just didn't think to use it this way since I knew I didn't want actual "state"

tony.kay14:09:48

I’m a bit tempted just to put the functions like that in CL state…it hangs around for the lifetime, is accessible by keyword, supports destructuring in lets…

thheller15:09:54

but then you have icky non-data things in your beautiful clojure maps 😉