Closed qrilka closed 9 years ago
Yeah, this is a fine place to discuss Fay ideas/issues.
Probably writing a wrapper to one of the existing templates is an OK approach. I'd also like to try a blaze-like approach. Haven't got round to it yet.
There seems to be interest to use Angular as well, but I don't know if anyone has started working on it yet: http://www.yesodweb.com/blog/2012/10/yesod-fay-js
Something blaze-like would be nice, if we could use/write some reactive bindings for it as well that would be even better
@bergmark Definitely.
Intermixing JS framework and Fay (as in Michael's post you refer to above) does not seem to be a good solution here as I'd like to define models in typesafe Fay and not in JS. And what about ReactiveMVC what it was written for?
@qrilka Maybe if you wrapped the JS framework with a type-safe interface it wouldn't be able to generate any non-type-safe scenarios.
The ReactiveMVC thing was just a base-level interpretation of backbone.js. It's the fundamental of FRP without being fully declarative. I simplified it a bit later. I'm sure there are much better things out there.
@qrilka I'm guessing they want to wrap angular in yesod somehow, maybe with some julius thing for fay?
I will try to create a wrapper prototype for Ember.js. BTW is it possible in Fay to create JS object with disired fields? I'm not sure how this could be done in typesafe manner. And without JS objects at the moment I don't see an easy way to imlement Ember.js wrapper
@bergmark As far as I understand current Michael's plans is to improve yesod-fay package and example with Angular was done before and used only typesafe URLs for REST interface used by Angular
@qrilka
BTW is it possible in Fay to create JS object with disired fields? I'm not sure how this could be done in typesafe manner.
If you have a value data Foo = Foo {bar::Int,zot:String}
then you can make an FFI function foo :: Foo -> …
and Fay will serialize that value to {"_instance":"Foo","bar":…,"zot":…}
. Or alternatively foo :: Automatic a -> …
, which can automatically serialize data
types.
@chrisdone Cool, will try this out later
And if the JS API is picky and doesn't like the instance
(not _instance
!) property you can do (untested!)
data Object = Object
dropInstance :: Automatic a -> Ptr Object
dropInstance = ffi "(function () { var o = %1; delete o.instance; return o; })()"
Sounds good.
I'm planning to write some bindings for AngularJS in Fay. I'll certainly be striving for type safety, though I'm not sure how far it might get. The underlying Javascript is always untyped, but then so is x86 and ARM.
It wiould be interesting to take a look at your solution so share some link if something will be available
I draw your attention to the word "planning" :P I'm hoping to get a bunch done on that this weekend, but I'm also giving a talk on Sunday that needs sorting out between then and now. Since others are waiting to see how it goes, I'll leave the Yesod/Fay/AngularJS integration for later and just use my existing Node server, and try to rewrite my client-side Angular-powered Javascript with Fay. I can worry about porting the server later.
My general scheme is to define Fay functions to register Angular controllers, directives, and services using the FFI. Probably routes as well. The tricky part is Angular's dependency injection. What will that look like on the Fay side, and how will you access the scope variables in Fay? The solution is probably an Ng or Angular monad that captures all of these things and generates the appropriate Javascript on the other end.
I'm hoping that the injection can be mostly implicit: that you'll have functions that access $scope, or $http, and the monad will just observe that you're using them and add them to the injection list. I'll follow up here with a Github repo link once I have something to show.
Chris, have you thought on how to do the blaze-like approach? One of the benefits for blaze-html is the use of monads and monoids to provide nice dsl. If I understood correctly, fay doesn't support typeclasses so monoids and do-syntax are out of the question.
Not yet. There is a way to do monads (see examples/ and tests/) but not proper monads. You can still just have an operator for combining EDSL thingies, though.
Spring cleaning. This is too vague to belong on the tracker.
FRP in Fay would be very nice -- something like https://github.com/Matt-Esch/virtual-dom
I have looked through fay examples and everywhere I see manual DOM construction/manipulation e.g. here - https://github.com/faylang/fay-server/blob/master/src/Client.hs#L103 For relatively small application it is OK, but for large UIs I think it would be very cumbersome. Using some kind of templating would be more convenient. At the moment I find Ember.js appoach (except that it is in js) quite good - it is very easy (at least for me) to see where the data comes from into HTML and what handlers will be called for buttons etc. In fay-server I see ReactiveMVC module (which could help in reproducing some functionality of Ember.js in Fay though not about templating) but I could not find any example of its usage. BTW I'm filing this issue (mainly a question for discussion) because I did not find anything like mailing list or google group about Fay.