Fork me on GitHub
#hoplon
<
2017-07-12
>
thedavidmeister01:07:36

@flyboarder the (cell= (and data value)) was something i tried too. yes, it evaluates any time either data or value changes but it only ever returns value, the do! will only trigger on the return value, not simply cell execution

thedavidmeister01:07:42

that's just because and only returns the last truthy value, but even if it returned the whole thing, we don't want data to get serialized into our input value...

thedavidmeister08:07:26

@flyboarder i'll try to write a nicer version of my proposed fix

thedavidmeister08:07:52

i haven't used alts! before, but i think this is what it's for

thedavidmeister08:07:14

(and (sequential? value)
               (every? cell? value))
          (let [vs (apply javelin.core/alts! value)]
           (do-watch vs #(do! elem this (first %2))))

thedavidmeister08:07:50

seems very close to what i want

thedavidmeister08:07:40

but for some reason the initial value of vs created by alts! drops the first value in the sequence so that (first %2) sees data rather than value

thedavidmeister08:07:20

i'll play around with it more later 🙂

thedavidmeister08:07:04

conceptually it's very close to the (cell= (and data value)) approach

dm309:07:03

I’d rather there was something explicit to serve this issue, e.g. (input :value (hoplon/two-way :cell value-cell :depends [data]))

dm309:07:33

then you can add either your own do! multimethod on top which will implicitly create that from [value-cell data] or abstract any other way you like

thedavidmeister12:07:23

@dm3 but it's not 2-way, that's the point

thedavidmeister12:07:28

it's avoiding 2-way

dm312:07:40

yeah, maybe not the best name

dm312:07:58

but we somehow need to express what it’s about

thedavidmeister12:07:56

i thought alts! more or less did what you're suggesting, right?

thedavidmeister12:07:15

creates a cell that evaluates when any of a list of other cells changes

dm312:07:20

well, when you see (input :value [x y]), what would you think?

dm312:07:28

what’s the value of that input?

dm312:07:50

or (input :value (alts! x y)) for that matter

thedavidmeister12:07:51

what, if i know hoplon or don't know hoplon?

thedavidmeister12:07:09

because if i don't know hoplon i have no idea what the value is

dm312:07:23

value is an attribute on input, no?

thedavidmeister12:07:34

sure... initially

thedavidmeister12:07:45

because cells have a time model

dm312:07:53

yeah, but [x y] isn’t a cell

thedavidmeister12:07:00

x and y both are though

dm312:07:08

what if y isn’t?

thedavidmeister12:07:17

(and (sequential? value)
               (every? cell? value))

dm312:07:32

what I’m trying to say - I think this deserves a more explicit treatment

dm312:07:41

rather than encoding its type into a sequence

thedavidmeister12:07:02

i see what you're saying

thedavidmeister12:07:32

but the current behaviour is implicit based on whether something is a value, function or cell

thedavidmeister12:07:50

what do you think (input :focus x) does?

dm312:07:25

as you said - we already have 3 types supported

thedavidmeister12:07:44

but if x is a function, it doesn't even trigger do! it triggers on!

dm312:07:54

I don’t think adding a 4th implicit option is a good idea

thedavidmeister12:07:44

so, when i was first learning hoplon, this was 100% something i had to learn

thedavidmeister12:07:58

but now that i know hoplon it makes perfect sense

thedavidmeister12:07:16

i don't think having 3 implicit options and 1 explicit option is a good idea

thedavidmeister12:07:34

it should be internally consistent either way

thedavidmeister12:07:53

hell, i'd probably support a proposal that if you pass a list of functions, to bind them all as event handlers 😛

thedavidmeister12:07:55

or maybe there's an explicit api and an implicit one and you use whatever is comfortable

thedavidmeister12:07:39

e.g. :on/click vs. :click and passing anything other than a function to the former is an error

dm312:07:02

well, I’m not a fan on overloading this thing even further

thedavidmeister12:07:25

i don't necessarily disagree with your criticism of how it works

thedavidmeister12:07:38

but this bug is actually really bad for what i'm trying to build

thedavidmeister12:07:53

and i don't want to deal with the implicit/explicit can of worms if i can avoid it

dm312:07:54

like what if you want to intepret a sequence of cells as and instead of or

thedavidmeister12:07:12

it's the first value of alts!

dm312:07:19

it’s or

thedavidmeister12:07:36

because a falsey value in the first slot will still trigger

dm312:07:38

right 🙂

thedavidmeister12:07:42

;; Creates a formula cell whose value is a list of changed values in the cells cs.

thedavidmeister12:07:20

imo that seems like the most natural fit for interpreting a list of cells anyway

thedavidmeister12:07:50

because and and or already exist and work better inside a cell than outside

thedavidmeister12:07:44

the only "trick" that i'm using is extracting the first item in the list as "the value"

thedavidmeister12:07:56

that bit i'll admit is a bit of hand waving

dm312:07:49

have you explored mutation observers?

thedavidmeister12:07:10

well that is 2-way data, right?

thedavidmeister12:07:41

and, no, to answer your q

thedavidmeister12:07:53

i assume it would work though

thedavidmeister12:07:15

worst case scenario you get an infinite loop where "changing" the value to the same thing triggers another "mutation"

thedavidmeister12:07:05

potential scenario is that there are weird bugs where you type stuff and the keys you press flicker in/out of existence as data propagates around javelin and back into the DOM

thedavidmeister12:07:37

best case scenario is that you're reading from the DOM, so it's 2-way i think

dm312:07:35

not sure how it’d work

dm312:07:53

if Hoplon defined some known attributes as being mutation-observed

dm312:07:57

like input:value

dm312:07:27

then on mutation you’d call the callback

thedavidmeister12:07:13

i'd like to see more support in hoplon for the various *Observer APIs that are maturing in general

thedavidmeister12:07:38

but i don't know if it's a solution for my current problem, or even if it is, whether it's a good idea in this case

thedavidmeister12:07:34

seems like we have to pick the least bad option out of:

thedavidmeister12:07:47

- have a known bug that is pretty bad in some situations

thedavidmeister12:07:02

- add to the implicit api for do!/on!

thedavidmeister12:07:15

- have an implicit/explicit split in that api

thedavidmeister12:07:21

- do something with 2-way data

dm312:07:10

I’d have to play around with this issue to actually completely understand why we get the result that we get

dm312:07:40

and explore mutation observers as a possible solution once I understand

dm312:07:50

only then I’d consider adding something to Hoplon core

dm312:07:03

so you might be a step ahead

dm312:07:15

otherwise I’d use a separate attribute with a special do! which understands a seq of cells

thedavidmeister12:07:08

the issue is that i cannot sort inputs on their value

thedavidmeister12:07:20

so, for example, if i have a form with a table layout and i want to click sort, i can't do that 😞

dm312:07:33

is it because your inputs are encapsulated and set :value to something you pass through?

dm312:07:54

I mean - why doesn’t the custom attribute solution work in your case?

thedavidmeister12:07:07

why should i need a custom attribute for such a basic need?

dm312:07:33

you shouldn’t! 🙂

thedavidmeister12:07:36

i mean, sorting elements is hardly advanced UI-fu

dm312:07:00

but I somehow feel that the problem/solution space isn’t explored sufficiently. I may be wrong!

thedavidmeister12:07:18

so... the short version

thedavidmeister12:07:27

after days of investigation

thedavidmeister12:07:59

is that the thing that makes do! work at all is a do-watch on whatever cell gets associated with :value

thedavidmeister12:07:46

so if that cell doesn't change its value, which is possible during sorting operations when you have multiple elements with the same value, then the do! is not triggered

thedavidmeister12:07:03

so it looks like values are "copied" after the sort rather than "moved"

thedavidmeister12:07:24

e.g. 1 1 2 should becomes 1 2 3 if you change the first 1 to a 3

thedavidmeister12:07:46

but it looks like 3 2 3 in the UI because the first input retains the value 3 and hoplon changes the last input to 3

thedavidmeister12:07:20

when hoplon sets the last number to 3 it must also set the first number to 1 to "move" it

thedavidmeister13:07:17

so a mutation observer can probably detect that you typed the number 3, but so does the :input event, so what next?

thedavidmeister13:07:48

what we can do though, is trigger do! when either the value cell changes for a single element or on all the elements whenever the overall sort order changes

dm313:07:19

ok, so we have to have a sequence of input -> reset! cell -> sort -> apply do!

thedavidmeister13:07:51

yeah basically, so the sorting "redos" all the elements

dm313:07:03

which we have now, but apply do! happens only where the value did change

thedavidmeister13:07:17

something in between

dm313:07:26

it’s tricky to explain succinctly

thedavidmeister13:07:40

which is probably why the bug has survived so long

thedavidmeister13:07:52

it's basically because when you have elements in a for-tpl it doesn't actually re-order elements in the DOM

thedavidmeister13:07:00

it just binds values to DOM attributes

thedavidmeister13:07:06

which simulates a sort

thedavidmeister13:07:11

but the simulation is not perfect 😕

thedavidmeister13:07:01

i actually wrote a test for the issue, so if you want to mess around with mutation observers i can plug it into the test and see how it goes 🙂

dm313:07:36

would love to, but not sure if when I’ll have the time 😞

thedavidmeister13:07:11

mmm, i know that feeling

thedavidmeister13:07:14

actually my fix doesn't totally work anyway because alts! doesn't quite do what i expected

thedavidmeister13:07:29

so i've still got work to do on this

thedavidmeister14:07:13

oh, alts! is not what i want at all!

thedavidmeister14:07:03

or at least, not the way i'm using it

thedavidmeister14:07:21

(and (sequential? value)
               (every? cell? value))
          (let [vs (apply javelin.core/alts! value)]
           (do-watch vs #(do! elem this @(first value))))

thedavidmeister14:07:27

@micha @alandipert either of you have thoughts on ^^?

thedavidmeister14:07:24

also, what is the process for reviewing/merging PRs? https://github.com/hoplon/hoplon/pull/189/files should be a lot less controversial

flyboarder22:07:40

@thedavidmeister #189 doesn't seem controversial, I can merge that, it's safe enough 😝

alandipert22:07:22

@flyboarder @thedavidmeister yes looks good to me too - merge at will

flyboarder23:07:55

Just going to put this here....