purescript-virtual-dom icon indicating copy to clipboard operation
purescript-virtual-dom copied to clipboard

Use foreign opts

Open fluffynukeit opened this issue 10 years ago • 8 comments
trafficstars

This PR includes two changes beyond PR #6.

The first is a leaner, more convenient definition of thunk that automatically handles converting null vtree with Nothing, or non-null to Just.

The larger and more philosophical change is adding increased type safety with new dependency purescript-foreign-options. The library handles conversion of Maybe, Either, callback functions, etc., from PS conventions to Javascript conventions. The configuration options for vhook, widget, and vnode must now contain prerequisite fields and types in order to compile.

The updates to thunk are largely orthogonal from the options changes, so if you only want one or the other, just let me know and I'll update either this PR or #6 as requested to make the merge easier.

fluffynukeit avatar Jan 11 '15 00:01 fluffynukeit

I like it. I'll have a bit of a play before merging though, and see if anyone else has any comments too. (@paf31?)

garyb avatar Jan 11 '15 16:01 garyb

I've not really been keeping up to date with this library, but I'm familiar with the options library, and the approach makes sense given the problem.

There is also the purescript-options library which takes a different approach to options objects, so maybe that's worth a look too.

paf31 avatar Jan 11 '15 18:01 paf31

@garyb, we had some discussion of these approaches recently at purescript/purescript-foreign#20. The main change to purescript-foreign-options since then is the addition of the Opaque constructor to protect parts of the options record from conversion.

fluffynukeit avatar Jan 11 '15 19:01 fluffynukeit

Thanks, I was sort-of paying attention to that discussion but had intended to look it up again for this. :)

garyb avatar Jan 11 '15 20:01 garyb

I definitely appreciate the effort that went into this, and agree something like this is the right direction, but I think I'd rather keep it dumb and accepting anything in the props objects for now.

This library was intended to be a low-level thing that proper interfaces were built on top of, and since there's not a clear winner in the foreign-options department yet (I also have some ideas I'd like to try out) and it's not entirely overhead-free I think it might be worth holding off until we come up with something even better.

garyb avatar Jan 16 '15 21:01 garyb

OK, that's reasonable. If you try out something of your own, could you write a note in this PR about it? I'd enjoy taking a peek at any new approaches. Thanks.

fluffynukeit avatar Jan 16 '15 22:01 fluffynukeit

Would you consider taking the changes to thunk only? They are unrelated to the use of the options library, and they are more consistent with how vdom actually works internally. I can prepare a new branch including only that change to make it easier if it's something you're interested in.

fluffynukeit avatar Jan 26 '15 07:01 fluffynukeit

That'd be great, thanks.

garyb avatar Jan 26 '15 10:01 garyb