Fork me on GitHub
#hoplon
<
2017-01-24
>
qqq20:01:55

so Alan and I had this case, where old = [1, 2, 3, 4] and new = [0, 1, 2, 3, 4] // and we were wondering if there was a way to do this using just 1 node-insert instead of 4 node-updates + 1 node-insert

qqq20:01:27

We ended up considering this from the perspective of edit distances (as in gene sequence laignment); and stopped there.

alandipert20:01:00

ran across brenton ashworth's clj diff thing

alandipert20:01:02

along the way

micha20:01:27

this is a thing you need to manage in react a lot

micha20:01:38

they make it associative so you can diff efficiently

micha20:01:48

you add a primary key to each item

micha20:01:58

then it can compute the reshuffling

qqq20:01:02

why did hoplon decide against a 'primary key' ?

micha20:01:16

well there used to be a :reverse true option

micha20:01:21

with the -tpl

micha20:01:27

that lets you insert from the other end

alandipert20:01:31

oooh i forgot about that

micha20:01:38

nobody ever used it lol

alandipert20:01:50

yeah one idea i had was to reverse in css

alandipert20:01:03

definitely crazytown tho

qqq20:01:11

iirc, primary key != :reverse true -- since isn't it the programmer's job to specify the primary key ?

micha20:01:22

computing edit distange etc is NP problem i think

micha20:01:51

yeah the :reverse true solution is nicer in cases where it works

qqq20:01:56

it's not NP problem

qqq20:01:06

it's O(MN) worst, case and O(N d) if you know the edit didstanc eis at most d

qqq20:01:20

if two sequecnes are of length M and N, it's O (M * N) via dynamic programming

qqq20:01:32

if you know ahead of time the two strings differe by at most d diffs, it's O ( N * d) via dynamic programming

qqq20:01:40

[I implemented one of these a few nights ago 🙂 ]

micha20:01:46

isn't that the complexity of the current naive way too?

qqq20:01:09

I only know of one way, so it's probably the "naive way"

micha20:01:33

i mean in your example

micha20:01:45

M new nodes + N edits

micha20:01:30

there are also more subtle issues i guess

micha20:01:43

because this is the interface between mutable and immutable

qqq20:01:21

// no, since in the second case, the two strings are of length N, (N-d to N+d), but the running time is not O ( N N), but O(N d), which is better when we know before hand that only 2 or 3 items changed //

qqq20:01:53

so if N = 100, and d=2 (other string is ofo elgnth 98, 99, 100, 101, or 102), this is O(100 100) vs O(100 2)

micha20:01:05

strings are way easier than the dom

micha20:01:09

well than components

qqq20:01:13

but either way, I do think having . a'priary key' is better

micha20:01:15

since components may be stateful

qqq20:01:46

'edit distance' don't require strings; they can take any vector

micha20:01:10

like if you're typing in a input box, you want that dom object instance to stay associated with the thing you're wanting to type in

micha20:01:30

that is to say, replacing the input element with another one with the same contents is not good enough

micha20:01:35

because there is focus, etc

micha20:01:49

so you can't just rearrange things to minimize dom interactions

micha20:01:06

that's why hoplon doesn't try to do anyhting like that

micha20:01:19

the current setup is very simple to reason about

micha20:01:28

well as simple as we could make it anyway

qqq20:01:54

in hoplon, if I createda list of textboxs, typed in one of them (but state not recorded in a ny cell), then I inserted a textbox at the top of the list; ... does hoplon preserve the browser input ?

micha20:01:30

you would need the reversey one in that case i think

qqq20:01:28

I see; I guess, either case, this is not something that currently fits well in hoplon

micha20:01:59

the primary key approach could be doable i think

micha20:01:10

it would be like kv-tpl or something

alandipert20:01:47

i wonder if we could somehow protocolize the strategy

micha21:01:10

it doesn't exist (yet) 🙂

micha21:01:26

but some things to think about are like

micha21:01:03

(for-tpl [[i thing] (cell= (map-indexed list things))]
  ...

qqq21:01:50

kv-tpl would basically be like react's primary key, and would solve all of my complaints 🙂

qqq23:01:42

anyone here managed to use https://github.com/Day8/re-com hoplon? I like hoplon's frp model, but I also like re-com 's library

mynomoto23:01:51

@qqq that's pretty much incompatible with hoplon. To use that you would need to mount the react root on some place in the dom that could be created by hoplon but I think that's pretty much it.

qqq23:01:28

@mynomoto : now that you put it taht way, I don't see how this can work either

mynomoto23:01:42

Well that is not composable with hoplon, but re-com create react elements, so you can mount that like any react thing. You create the dom node with hoplon then use something like (reagent/render-component react-component target-element)

mynomoto23:01:59

I don't think that is a good idea, but it would work.