I just want to mention a few things to newcomers to programming and JavaScript. It may seem like everyone is telling you to use X and Y or your app will burn into a pile of ashes. JS is maturing (finally!) and our apps are going from static pages with JS sprinkles to logic heavy apps, more similar to mobile apps than wikipedia.
However, I believe that it’s really important to learn and feel the pain before using some of these libraries. Otherwise it’s just overwhelming and doesn’t make sense as to why they’re doing X in the first place. You’ll end up wasting a lot of time that could be used to build cool things!
It’s incredibly hard to learn about building a maintainable app before you make spaghetti code and feel the pains from it. If something works, stick with it and most importantly keep an ear open for when these shiny things may help you. You just want to know enough about it so that you know what tools you have in your tool chest.
It’s more important to build a great product than to fret about making perfect stack decisions.
Examples with shiny tools (anecdotal but potentially useful, feel free to stop reading here )
##react
I’ve used Meteor since 0.4 and have loved using Blaze. Until I had 2 years worth of cruft from rapidly changing and removing features. With two developers and no standard you were never sure what a template/script was doing. Lots of find
searches to see where Session was set and plenty of debuggers with Iron Router re-runs.
You end up getting really good at Blazes quirks but they never seem to vanish. Even with Flow Router and template variables it’s tough to keep things straight. Templates don’t compose well so having a 150 line template is not uncommon.
It’s also hard to tell if removing a thing will break another thing in a very certain context… until user’s email you about it.
After watching Pete Hunt use React in a Meteor app I couldn’t fathom why anyone would want to use all of that gobbly gook in their app. Blaze was clean! (well I thought then at least, the HTML was clean but not its JS).
Then I had to build a mobile app. React Native just came out so I subscribed to Egghead and in a weekend built my first RN iOS app! Compared to Objective-C the View
and Text
tags were much easier than Cocoa.
Then after some hacking (before the MDG magic sauce!) I dropped React into a fresh Meteor app and got started with a todo app right away. There was very little change from ReactNative except for using div
instead of View
. Tinkering with this taught me enough to keep my ears open when problems came down the road.
Later when having more issues with a Blaze app, I added React and changed a very small section while leaving the rest. I noticed that very little of the React code was buggy and gradually more and more got replaced (as features got added/updated/debugged).
In retrospect, the main benefit is a strict flow of data, declarative data, and a cohesive bond between templates and template logic. You could build a ‘widget’ without any context of the outside world which meant you could keep the entire flow of the widget in your head at once. Not easy with Blaze.
Takeaways… if you enjoy Blaze, great! Use it and build something cool. If you have spare time and would enjoy it, learn React (or Angular but that takes more time) so that you know what tools you can bring out in the future.
###Flux I started building a React Native app and was *very confused* with flux. I just ignored it and got to work using good 'old `this.setState`. It served me well for quite a while. Then it started getting confusing when editing/bugfixing. Then I recalled flux helped with this and only then dove into it. This time things made sense as I had more context. I *gradually* folded it into the app with new features and when I was debugging/changing old modules. I didn't have the time or $$ to stop building to swap it out.
With a Meteor context, use getMeteorData
until it stops working for you. Local UI state (not database data) can be stored in a component with this.setState
or it can be stored globally with Session.set("react:posts:fooIsHidden")
.
When your app gets to a point where you’re not sure where data is coming from or how the data got changed… start reading up on Redux (vanilla flux is too verbose).
###GraphQL
I’ve maintained a few APIs in my Meteor app for other things to consume and it’s always been a huge hassle. It starts off very simple and as things change, it gets hard. Maintaining V1/V2/V3 versions is very verbose and hard to change. REST makes things hard because you typically can’t get all your data with one request, unless you’re making custom endpoints. Sending just the fields you need makes things very complex on top of all of this but is required for mobile.
GraphQL looks complex at first but once you wrap your head around it, it’s simpler than making a REST API and fixes all of the above issues (and more).
In a Meteor context if you’ve struggled with sending multiple collections to the client or had to drop down to the complex low-level publish API, then GraphQL can help you out. If you have had to fetch non-reactive data then GraphQL can help you out in spades… Currently you need to use Meteor Methods to return data (like a REST custom endpoint).
GraphQL is main made up of schemas similar to Simple Schema. These are composed together to fetch and update data in a safe way. It also gives you autofill tooling to help build queries (note, in the future GraphQL will have optional types for rapid prototyping).
Again, if you’re not having pains don’t worry about it (well unless you like learning/tinkering on the weekend, then go for it!).