outwatch / purescript-outwatch

A functional and reactive UI framework based on Rx and VirtualDom
https://outwatch.github.io/?lang=purescript
Apache License 2.0
34 stars 5 forks source link

[WIP] Monadic api + refactoring + way too many things #9

Closed rvion closed 7 years ago

rvion commented 7 years ago

based on https://github.com/OutWatch/purescript-outwatch/issues/8#issuecomment-290539926, I've toyed a little bit the the code.

@LukaJCB I'm just sharing it now so you know what I have been experimenting with :) there is many additions / fixes / refactoring / renaming / optimisations / changes I wanted to do before submitting, but since it's becoming much bigger than I expected, I decided to share the progress here.

I'll edit this post and add a description over the weekend

LukaJCB commented 7 years ago

Wow, that's some really great work! Will give you more feedback as it comes to me :)

LukaJCB commented 7 years ago

So I've had some time to play around with this and I'm incredibly impressed with how easy and clean it all is. If I were the only target audience for this framework, I'd probably go with this immediately.

However, I'm not sure if Users will have the same reaction, most people I've shown OutWatch expressed their trouble with getting an intuition for Observables and Streams, I don't think handing them a monadic api and monad transformers is going to be an easy sell.

My main problem with the proposal, however, is not the extra layer of abstraction (I don't think we can manage effects succinctly without them), but it's translation into Scala. Scala's for notation is not as expressive as PureScript's do and can't really express the monadic api AFAIK (feel free to correct me if I'm wrong)

I'm thinking maybe we could support two APIs on the PureScript side (if you're willing to help), I feel like you put a lot of work into this as well :)

rvion commented 7 years ago

@LukaJCB

So I've had some time to play around with this and I'm incredibly impressed with how easy and clean it all is. If I were the only target audience for this framework, I'd probably go with this immediately.

thank you very much !

However, I'm not sure if Users will have the same reaction, most people I've shown OutWatch expressed their trouble with getting an intuition for Observables and Streams, I don't think handing them a monadic api and monad transformers is going to be an easy sell.

I completely agree. I tried to keep both version, and plan to experiment a lot of small things to help that. For instance, I'm planning this PR to offer 3 versions: one with transformers and MonadState m constraints, one with some concrete HTML newtype, and the pure version

My main problem with the proposal, however, is not the extra layer of abstraction (I don't think we can manage effects succinctly without them), but it's translation into Scala. Scala's for notation is not as expressive as PureScript's do and can't really express the monadic api AFAIK (feel free to correct me if I'm wrong)

I don't really know for now. I'll think more about it, but you know scala better than I do.

I'm thinking maybe we could support two APIs on the PureScript side (if you're willing to help), I feel like you put a lot of work into this as well :)

Yes, I really hope we can support both! :)

rvion commented 7 years ago

🍏 EDIT: problem solved (bug was probably in purescript-rxjs)


@LukaJCB I haven't spend too much time searching yet, but could you help me or give me a pointer on that :

I'm trying to get some way to deal with observable (HTML e)

x = do 
    sliderEvents <- createHandler_ []
    let imageLists = sliderEvents.src
          # map \n -> img_ (src_ "testtest")
--                    ^ this is not an `Observable [VDom e]` but an `Observable [HTML e]`

I didn't find a simple way to write some instance for it:

instance childrenStreamReceiverBuilderM :: ReceiverBuilder ChildrenStreamReceiverBuilder (Observable (StateT (Array (VDom e)) (Eff e) Unit)) e where
    bindFrom builder obs = ...

so I tried to use some low level unwrap from Rxjs

ul_ do 
    input_ do
        type_ "range"
        inputNumber_ sliderEvents
        valueShow_ 0
    test <- lift (unwrap (map build imageLists)
    div_ (children_ test)

where unwrap is https://pursuit.purescript.org/packages/purescript-rx/1.0.0/docs/Rx.Observable#v:unwrap

unwrap :: forall eff a. Observable (Eff eff a) -> Eff eff (Observable a)

but it throw exceptions on some some internal chrome VM js files x)


I'll try to dedicate more time about that some evening this week, but any pointer or help would be welcome, as I'm not 100% familiar with OutWatch internals

rvion commented 7 years ago

Ahah, just clone this repo on a new PC. I was planing to take some time to fix the bug, but MAGIC , the bug is gone :) I guess the fresh install resolved a few versions differently and that the bug was in some previous version

LukaJCB commented 7 years ago

Hey @rvion sorry for getting to you so late, I'm currently attending a conference and didn't have the time to check out your problem in detail. Great that it's fixed now though. And yeah, I'm not really happy with the purescript-rxjs dependency on my own repo, but I'm sure we'll maintain some kind of stability soon. :)

rvion commented 7 years ago

no problem :) thanks anyway ! 👍

hope to have much more to show soon

rvion commented 7 years ago

@LukaJCB I've reach some okay point. It's still WIP, but the code is reviewable and can be played with :)

Do you think you will have time to take a look ?

If you run the examples, I'd be very happy if you could help me with the bugs I spoke about here: https://github.com/jasonzoladz/purescript-rxjs/issues/16#issuecomment-292742827, as I'm quite stuck for now