Fork me on GitHub
#re-frame
<
2019-07-03
>
Ahmed Hassan10:07:02

How can we Normalize app-state in re-frame like Fulcro or EntityDB?

carkh10:07:45

use datascript, write your schema, dump your data in. Bam ! normalized !

Ahmed Hassan11:07:22

What is size of datascript in browser?

Ahmed Hassan11:07:00

Is there any light-weight way to do it?

carkh11:07:15

entitydb is stand alone

carkh11:07:32

could use that

Ahmed Hassan11:07:08

Does EntityDB have similar Normalization to Fulcro.

carkh11:07:33

depending on the complexity of your app, you may win by using more heavy datascript though, if you have many data manipulation queries

Ahmed Hassan11:07:09

I understand Fulcro's pattern of normalization, i've played with entitydb but don't understand it's patterns.

carkh11:07:28

you know i lean more on the keechma side =)

❤️ 4
carkh11:07:43

it's the same thing really

carkh11:07:21

define your idents and relations, dump data in, fulcro, entitydb, datascript they all work the same way in this regard

Ahmed Hassan11:07:47

In re-frame you have to do this yourself.

carkh11:07:13

you don't even have to do it at all in re-frame, might be the best choice sometimes

Ahmed Hassan11:07:50

When data model get large you need some structure.

carkh11:07:00

i've done a re-frame app using datascript for keeping the business data

carkh11:07:26

but it was an electron app, so i never considered space requirements

Ahmed Hassan11:07:55

I want to work with Keechma, but not able to get start even hello world running. But I like ideas.

Ahmed Hassan11:07:18

Now I'm using reitit frontend routing with re-frame.

Ahmed Hassan11:07:44

It have controllers, that react on route change.

carkh11:07:07

if that works to you, that's all fine !

p-himik09:07:54

There is also https://github.com/vimsical/subgraph About a year ago or so I found that datascript is about 10x slower than plain maps-of-maps manipulations. Ended up with a heavily customized version of subgraph.

👍 4
Ahmed Hassan11:07:15

@U2FRKM4TW what did you found lacking in subgraph?

p-himik20:07:57

@UCMNZLJ93 Hard to recall right now. After a quick look at its usage examples, I can definitely say that I: 1. Removed the need for namespaces 2. Made everything more flat and much simpler (no more "give me the name of the friend of the friend of the...") Probably something else.

credulous19:07:08

I’m using Mapbox in my re-frame app, which renders to a canvas. I’m using the lifecycle methods to interact with it (component-did-mount, etc) which is ugly but seems to be the best way.

credulous19:07:17

A thing I need to do, which I’m hoping for a suggestion for, is to interact with some DOM elements that the mapbox thing creates. In particular when I create a pop-up on the map, I have to use javascript interop and pass a raw HTML string to a setHTML function on the map object

valtteri04:07:26

Hi @credulous! Following works for me with OpenLayers. I haven't used MapBox so I don't know if any of this can be applied but I hope you can achieve something similar. - create DOM element for the popup 'outside' the map component using React/reagent https://github.com/lipas-liikuntapaikat/lipas/blob/master/webapp/src/cljs/lipas/ui/map/views.cljs#L1000 - tell OpenLayers to render popups into aforementioned DOM element https://github.com/lipas-liikuntapaikat/lipas/blob/master/webapp/src/cljs/lipas/ui/map/map.cljs#L95-L98 - manually set the position of the popup overlay each time you need to render a new popup and inform the 'outside world' to display the popup https://github.com/lipas-liikuntapaikat/lipas/blob/master/webapp/src/cljs/lipas/ui/map/map.cljs#L158-L162 This way you can render whatever into the popups with react/reagent (and control if they're visible or not without direct DOM manipulation). This strategy was pretty tedious to setup initially but it has been working remarkably well for me.

credulous19:07:07

Again, ugly. But now I want to dismiss those popups from another part of my application, based on an app-db event.

credulous19:07:38

Do I need to create an effect handler, or is there some kind of way to have a reaction function that just subscribes to the change, the way a component would?

isak20:07:09

@credulous you just call render again (with a different target element) from your lifecycle methods. Portals from React may also work (don't know enough about your usecase to say): https://reactjs.org/docs/portals.html

isak20:07:34

Or, if you use the inner-outer component strategy, you can eliminate the need for lifecycle methods: https://github.com/Day8/re-frame/blob/master/docs/Using-Stateful-JS-Components.md

mathias_dw20:07:39

hi, I'm using re-com's scroller component, but I need to programatically scroll to some position in the content. Does anyone know of some example code I can look at?

isak21:07:03

I would try just getting a ref to the component, then call the method on the HTML element manually https://gist.github.com/pesterhazy/4d9df2edc303e5706d547aeabe0e17e1

mathias_dw12:07:31

thanks isak, I'll try that!

mathias_dw20:07:02

(I know it's a re-frame channel and re-com isn't exactly part of re-frame, but it's the closest channel I could find)