A mobile, desktop and website app with the same code
github.com
github.com
It happened to be really convincing (at least to me) in the case of a small project like the one I did but I am also convinced that for bigger projects people should be very careful and think twice before going with this paradigm.
I'm not sure how much value your paradigm will bring to a project -- 90+% of the non-boilerplate code in most React components is inside the render function, so I'll probably just deal with the very small amount of duplicated code rather than adding the complication of the paradigm you're using.
However in a larger project, duplicated code is much more expensive, so I think your paradigm would be useful there...
About the 90% of code inside the render functions, it made me think about the time where people were complaining about huge Angular controllers. I agree that render function can be large sometimes but I think that if 90% of code component is in the render function, you should probably move some code to the stores.
And I'm firmly in the "lots of tiny little components" camp, so I don't have any large render functions. That's also another reason I'm not going to adopt the pattern the OP suggests -- that pattern uses 3 files per component.
What kind of paradigm do you think you'd use for a larger project? Also do you think you'd stick with Flux vs Redux/Alt/etc?
You are right about flux/redux question, I started this project 3 months ago and let it on the side for a long time, but I would definitely go with Redux if I had to redo it now. Same for a bigger project. I have never used Alt so I can't tell.
Wise words.
How you would have done for a larger project? And also if we remove mobile from the equation, but a cross platform desktop app?
My guess would be just to use the correct "packager“ for it. I used NW.js which today seems to be overpassed by Electron. I think you need to get the right one to build a windows app.
Question- how much extra work would it be to add Android and/or Windows Phone support with react-native?
Yes, it uses JS in the background but uses native widgets, which results in a much better user experience.
In my first programming job, there were a few senior programmers who were then in their 50s, meaning they started programming in the 70s (before microcomputers). In those days, the way you became a programmer was to major in electrical engineering. That's why even now, a number of top universities (MIT, Berkeley, Ann Arbor, Rice) have combined departments of "electrical engineering and computer science".
How many C++ and Java programmers these days know how to work their way around NAND gates, digital logic, and RCI circuits? How many know how a transistor works? How many know how to build a mux in hardware, or an adder, or what's in a RAM cell?
I'm sure there are some, but by and large, I think it's an improvement that we don't think about digital logic and binary representations when we write our program. The cycle of moving up the abstraction hierarchy has been going on since high-level languages were invented in the 50s. Today's tools and frameworks are the low-level building blocks of tomorrow.
The movement to JavaScript is a product of web developers branching out into other areas (great!) without taking the time to learn another language (not so great :/). I don't think performance is an end in and of itself, and I don't turn my nose up at picking a technology because developers and expensive and processing power is cheap, but I still think writing everything in JavaScript is a step backward.
edit: Accidentally wrote developers are cheap and processing power is expensive :P
Raising the barrier to entry doesn't "raise the bar" when it comes to software quality. It just adds artificial difficulty.
The hard part about writing software shouldn't be Hello World. It should be building a user experience people enjoy. The less steps to get to that point, the better.
Ditto PHP, Node.js, Rails, and any other technology aimed at opening up programming to a larger audience.
This trend has a while to go: while there are vastly more programmers out there than when I started programming, there are still vastly more non-programmers than programmers, and I believe that ultimately mastery of machines will become as important as literacy.
Your concerns involve bundling whole web browsers with the desktop applications. We'll probably see a desktop version of react-native in the near future, making things much more lightweight.
[0] Without barely any GUI, it was mostly a canvas.
As compared to what? Compared to other interpreted languages, sure, but you're looking at least an order of magnitude compared to other VMs.
The performances of editors like Atom or Brackets tell us another story.
Web UIs might be fine for an LOB app but then, an LOB app doesn't need to be a desktop app. No, current JS engines (JS is a language, it doesn't have performances) are definitely not fast enough. Compared to the kind of performances that can be achieved with the JVM or QT.
This is not true. Unless you have a god-compiler that takes your JavaScript and spits out compiled code that doesn't use dynamic typing or a GC, the nature of the language has a significant influence on performance.
Well , my point is JS is a spec. You can argue that some language features will make the language slow(er than statically typed languages),and I'd agree.
Anyway, the discussion is the use of JS. The language is fine but the UI "library" is not (a whole web rendering engine).
Runs as: - Mobile (Phonegap) - Native (nw.js) - Website - Chrome extension
with exactly the same codebase.
KeyboardRender.ios.js: https://github.com/benoitvallon/react-native-nw-react-calcul... KeyboardRender.js: https://github.com/benoitvallon/react-native-nw-react-calcul...
I'm wondering, though, if we can take this a step further and write Keyboard as the exact same code by composing it with more general components like `<View>` instead of `<div>`. This will require inline styles instead of class names, though.
I theorize that this will be made a little easier for you with the use of react-native-web: https://github.com/necolas/react-native-web
Cool project, though, thanks for sharing. Code is very clean, I'll definitely be using it as a reference.
That's probably not a bad thing; at the moment there's duplication of inline styles for the mobile view and styles in a CSS file for the web/desktop.
So, the mobile app is an actual native app, with no phonegap / webview.
The desktop app is a webkit browser packed as its own application.
And the server app is a single-page app run in the browser and served from a server.
Correct?
https://code.facebook.com/posts/1189117404435352/react-nativ...
Eventually you'll end up with some shared code and other platform specific code and you'll wonder why you don't just split up the codebase into individual applications (that can easily be worked on by independent teams). You can still have a shared dependency that handles logic, but you can iterate on each application independently.
The key difference here is that user expectations are completely different between a mobile app, a desktop app (either native or node webkit), and a web app - at the moment I would say that its rare to see any app share the same codebase (not including shared libraries/dependencies) for all of those. As this post shows, its not impossible, but there are still some tradeoffs.
If I was starting a brand new application that needed to work across all platforms, I would still consider having independent code bases sharing a library as a dependency rather than having a single codebase for everything - especially if I wanted to be sure to have the best possible experience for each platform.
On the other hand we're earning a lot due to all the unnecessary and wasted resources we have to sell to meet performance expectations of our customers ( and those guys happily buy it ) you could reach with 1/1000 probably 1/100000 of the MIPs by utilizing native C.
Utilizing react is not even programming or engineering. That's assembling. rant off
What's different this time?
It is popular (Java was and still is), it is backed by a big company (Java too), it only needs Javascript, which all devices have (Java only needs a JVM, which all devices used to have).
Well, I sure hope for all the folks involved it really is the future. At least, it may well be for the next few years.
No, it really didn't. For a time after "Java Web Start" was introduced in 2001, java had (has) a pretty decent story for distributing application (big run time dependency, problematic java updater non withstanding).
But I think the biggest problem java had/has is the mix of java being a hopelessly verbose, and arguably rather primitive language that's a bad fit for both AWT and (to a lesser degree) Swing. It's almost comical to contrast "hello world" with swing/java and with swing/jython (or jruby) - it's not that the UI toolkit is unusable, but it's not a good fit for the biggest use-case: simple business applications.
I should add that I think kotlin looks like a pretty perfect match for "the good parts of java without any added complexity".
> What's different this time?
Modern JS is arguably a better fit for simple GUI programming than modern java is.
Personally I've switched my focus from native iOS to React & React Native.
I think currently there are more languages compiling to JS then to JVM. :)
WASM holds a lot more promise for all of these problems.
https://github.com/benoitvallon/react-native-nw-react-calcul...
Lots of ad-hoc global variables like _lastPressedWasEqual. Is this idiomatic?
So... global variables?
I also noticed that we have a Store (which I interpret to mean model-layer) handling key events, e.g. "processBackKeyPressed()". Is that common too? From my outsider's perspective, this looks like a layering violation.
I don't think it's a "key event" in the sense you're imagining. The store is a black box around a calculator device with emulated physical buttons, so "back key pressed" is one of the store's fundamental actions. I might be wrong about this.
IMO same code base is just that, no ambiguities. In this example it would be the same js, html and css that run inside a different container (browser, nw, node or webview)
The point about everybody converging to the flat paradigm that evolved from the mobile web is a valid one. What is good for small touch devices may not be for large mouse-driven ones; the removal of affordances and button labels in particular is a problem in the new style favored by web designers.
However, I would also complaint against developers trying to make web applications feel like desktop ones, with window management and all, which is a similarly recurring and worrying trend.
Off topic but does anyone know people hiring freelance React Native? I'd really like to focus there myself. It's the future.
For instance, if a hospital is looking for someone to build an appointment management app for their patients, they don't care if you use Obj-C or JavaScript - they just want an app that works.
For personal taste I'd put a little PureScript or Haskell (with GHCJS) in the mix :)
But this web everywhere shit...
That might do it.