chandu0101 / sri

Build truly native cross platform (web,ios,android) apps using scalajs and react, react-native ,This project moved to new organization : https://github.com/scalajs-react-interface/sri#sri, new chat room : https://gitter.im/scalajs-react-interface/sri
Apache License 2.0
634 stars 35 forks source link

Evaluate using ScalaJS-React #3

Open mariussoutier opened 8 years ago

mariussoutier commented 8 years ago

ScalaJS-React is already pretty complete, and I think it'd be great if there weren't yet another way to write Scala.js + React. Is it possible to use ScalaJS-React instead of rolling your own facade?

mkotsbak commented 8 years ago

I agree. It should be the same as with native JS React, so that you could potentially could reuse some of the code/backends.

xsistens commented 8 years ago

@mariussoutier @mkotsbak i try to give you a first short answer. If you want a more in depth answer you have to wait for @chandu0101.

This project is relying on the loose coupling between the construction layer (react) and the presentation layer (react-dom for web and react-native for ios/android). This loose coupling was introduced in the 0.14 version of react, which is not yet supported in any of the stable versions of scalajs-react (first occurence of react 0.14 is in the RC1 version released today). But this project is older then just 1 day :D so @chandu0101 had to write his own facade for 0.14 react for this period of time.

For any questions about the further development of the sri project (especially the react-native part) and the combination with scalajs-react you have to wait for @chandu0101 answer to the questions.

PS: for the relay part i'm already working on a solution for scalajs-react.

chandu0101 commented 8 years ago

@mariussoutier @mkotsbak before going to any technical details i have more scalajs-react code base to take care than anyone else (except David (@japgolly) :p) .

ScalaJS-React is already pretty complete,

Its actually more than complete with dom dsl and cool FP stuff.

Is it possible to use ScalaJS-React instead of rolling your own facade?

The only part can be reused between Sri and Scalajs-react is core react(no dom/react-native stuff) , this boils down to raw react facade(< 30 LOC) and element construction factory/builder. Currently scalajs-react ReactComponentB is using old React.createClass , Sri element factory is based on new React.Component which is faster(a must feature for mobile first library like Sri) than React.createClass . In other words there is nothing to reuse from scalajs-react at the moment, infact scalajs-react can reuse sri element factory . That being said having common react core module between scalajs-react and sri would be awesome(to be honest its high on my wishlist), i am more than happy to work in that direction :)

mariussoutier commented 8 years ago

Thanks for the elaborate answer. Then how about aligning the APIs so the switch will be easier?

japgolly commented 8 years ago

Hi! Congrats on the release! :confetti_ball:

Sri element factory is based on new React.Component which is faster(a must feature for mobile first library like Sri) than React.createClass.

I didn't know that! Is that true? (I mean: are you sure?) Have you or anyone done any benchmarks, I'd love to see some numbers on that. Classes extending React.Component are less capable that ES3 style and React.createClass output - in the React docs they say some things are unsupported and bad luck basically (mixins, something about lifecycle methods too? can't remember). Therefore I wasn't planning on changing the scalajs-react to use it - from a Scala perspective it's just an impl detail. If you're saying there's a significant performance difference, maybe I should change it to use React.Component.

having common react core module between scalajs-react and sri would be awesome(to be honest its high on my wishlist), i am more than happy to work in that direction :)

That could be a very cool idea. At the same time though, I think it might be good to wait a while. Being separate for a while will cause us both to do things differently, the way each of us think is best, which provides more innovation, then we can see what each other did and probably learn from each other. Secondly, I already have plans to split scalajs-react into modules that correspond with React. At this point (v0.10 RC1) it looks pretty easy to do (I'll probably do it in v0.11 though - let things stablise). Once that's done I'd probably like to play around and experiment adding another module like react-native, or react-art or something.

So in summary, sounds great! but let's wait :smile:

chandu0101 commented 8 years ago

I didn't know that! Is that true? (I mean: are you sure?) Have you or anyone done any benchmarks, I'd love to see some numbers on that

Even i didn't know that when i first choose React.Component over React.createClass , but after i build my movies app using React.Component i felt its faster than my scalajs-react-native movies app.

https://youtu.be/fVd3N-o3P9w?t=1493

In above video Joe Savona from the Relay team at Facebook did actually mentioned that classes are faster than React.createClass , i bet they did some benchmarks internally!

keeping speed factor aside i suggest to support React.Component in scalajs-react , i don't say that React.Component is "The" way to go , react team experimenting with other options too module pattern but they definitely don't go backwards (React.createClass) .

I think it might be good to wait a while

Sure, but sooner the better! , i want scalajs to win at the end of the day :)

japgolly commented 8 years ago

Ok thanks for that info. It'll be pretty easy to pump out React.Component classes instead of React.createClass. I'll look into it. Using Scala.JS classes = ES6 though right? I worry that would make scalajs-react output JS incompatible with a number of browsers. I'll have to look into it. Maybe I'll add an option to choose which output it generates, support both.

Anyway, back to this issue.

I think it might be good to wait a while

Sure, but sooner the better! , i want scalajs to win at the end of the day :)

Well my open-source focus for now is scalajs-react itself. I've got to get the new release out and already there are a number of useful changes that I want to make in the next version. When I have a chance to breathe I want to spend some quality time on scalacss.

If sooner the better for you, feel free to send me PRs if there's something you need from scalajs-react, no problem! For the types of changes that I imagine you might want, probably good to check with my first before you start coding - I'd hate for you to do work only for me to have to reject it.

chandu0101 commented 8 years ago

It'll be pretty easy to pump out React.Component classes instead of React.createClass, I'll look into it. Using Scala.JS classes = ES6 though right? I worry that would make scalajs-react output JS incompatible with a number of browsers.

Glad you recognized React.createclass as legacy ,ES6 classes are transpiled to ES5 so no browser issues, and btw i already done that work so no need reinvent the wheel (unless my implementation is garbage!).

Well my open-source focus for now is scalajs-react itself.

Well ofc our focus should on react which will help scala.js community, and i truly appreciate your work, without any doubt if there was no scalajs-react i shouldn't have choosen scala.js at that time ;)

I've got to get the new release out and already there are a number of useful changes that I want to make in the next version.

I agree there are many changes , but i'am surprised when you left ES6 React.Component( landed in react 0.13). and i have a feeling that scalajs-react is focusing on individual project specific helper's than supporting core react features!

If sooner the better for you, feel free to send me PRs if there's something you need from scalajs-react, no problem!

I am afraid we both are not in sync, my proposal is to have a common core under some organisation that contains only way to define components nothing more. for this to happen i want to see scalajs-react ReactComponentB cleaned up not to have any dependency on dom, if its going to be huge work then we'll have common core with raw react facade and my ES6 way to build components and your scalajs-react core depends on that. let me know your thoughts on this.

japgolly commented 8 years ago

Glad you recognized React.createclass as legacy

I have not yet. Cheers for the links you sent me but I haven't checked them out yet so I'm not aware of React calling it legacy yet.

i truly appreciate your work, without any doubt if there was no scalajs-react i shouldn't have choosen scala.js at that time

Thank you @chandu0101 ! Very kind words, I'm happy to have been helpful :D

i have a feeling that scalajs-react is focusing on individual project specific helper's than supporting core react features!

My goal for scalajs-react is the best Scala experience and type-safety. I don't see the importance whether it generates ES6 classes or createClass under the hood. If one is better performance than the other then I see it as a performance issue and I agree with the value of performance. I don't see the value in shifting to it just because JS-land is. As Scala users we don't even really see the JS output. At least that's my perspective on that situation.

I am afraid we both are not in sync, my proposal is to have a common core under some organisation that contains only way to define components nothing more. I want to see scalajs-react ReactComponentB cleaned up not to have any dependency on dom, if its going to be huge work then we'll have common core with raw react facade and my ES6 way to build components and your scalajs-react core depends on that. let me know your thoughts on this.

I don't know if that's a good idea or not. It might be, it might not. But I should be blunt and realistic so as not to accidentally mislead you: even if I were fully convinced that it's a good move, it would be a long while until I'd be able to prioritise it as a task in my free time. Open-source isn't a paying job and the amount of altruism I can dedicate to it is limited and already pre-allocated :) PRs are a different story. The PR door is always open.

chandu0101 commented 8 years ago

wow i know where its going :P , ok I think it might be good to wait a while!