Fork me on GitHub
#re-frame
<
2020-04-12
>
kitallis08:04:46

I have a simple clojurescript thing that allows you to draw stuff on a canvas

kitallis08:04:58

(and then re-draws what you’re drawing next to it)

kitallis08:04:46

I’d like to turn this into re-frame app, and I have moved most things to re-frame outside this namespace

kitallis08:04:08

but I’m not sure how to go about this, there’s a bunch of event handlers that need to be attached to a paperJS canvas

kitallis08:04:20

Not sure where they will sit in terms of execution

kitallis08:04:58

There’s a few atoms that get updated as a result of these handlers

kitallis08:04:06

I’d want to move them to the app-db

kitallis08:04:30

Just looking for some general strategy (best-practice) kind of thing to get started

kitallis08:04:07

But that’s a lot simpler, it doesn’t really have any canvas-level handlers that need to be executed

p-himik08:04:08

If you treat the canvas and drawing on it as a black box, what are the events that might happen to it from the other parts of your app?

p-himik08:04:43

Events triggered directly on it by e.g. a user don't count - those are part of the black box in my question.

kitallis08:04:58

For now, nothing, it’s nearly a blackbox interaction that gets triggered when I land on that page

kitallis08:04:08

However, it will modify the app-db

kitallis08:04:30

And there might be other subtle interactions later, like because of some outside event, you cannot draw on this canvas anymore, etc.

kitallis08:04:49

But it’s fairly isolated I would say

p-himik08:04:55

Don't unroll such black boxes. Just create a component from it and pass something like :on-draw #(dispatch [::set-whatever-in-db %]) to it.

p-himik08:04:16

I definitely would not put paper and anything related to it into the DB.

kitallis08:04:41

I think, it’ll be pure data, not necessarily paper related, it’ll just be the paths that the user drew

kitallis08:04:58

(so that can be shot over websockets eventually)

kitallis08:04:56

But if I make a standard reagent component, I’d have to dispatch in component-did-update – is it alright to shoot off dispatch inside lifecycle methods?