Monday, March 16, 2015

In Which I Freak About How Cool Two-Way Data Binding Is


I’ve done a bit of a pivot in the last few weeks, focusing more on front end projects than Rails. In so doing, I’ve started working in AngularJS and you know what? I like it. I like it a lot. In fact, you might say I’m really gaining a lot of – wait for it – Angular momentum! ANGULAR MOMENTUM! Ha! Let me furnish you, gentle reader, with the salient hashtags to commemorate this moment:  #physicsjokesarehilarious #somuchlolz #micdrop


This video is the key to unlocking the physics hilarity, if angular momentum is new on you. 


Okay, back to business. There are a ton of things that are really interesting to talk about with regard to Angular (not the least of which is, “What is Angular?” My apologies. I am writing out of order. I’ll say more later about what Angular actually is/does. For now, let’s go with a gigantic oversimplification and say it’s kind of like Rails, but faster and prettier and is only kind of like Rails.)

Today I’m just gonna talk about one of the features of Angular that is, IMHO, seriously rad. What am I talking about? Two-way data binding! And so now you’re like, “That’s dumb. That just sounds like stapling a spreadsheet to some walkie-talkies.” Okay, first of all, I love stapling, spreadsheets, and walkie-talkies, so nothing about that sounds dumb to me.

More importantly, though, if you squint at that sentence while thinking of metaphors, you might see that two-way data binding maybe kind of it is that. Let's put a pin in that.



Ah. Once again, I discuss the thing without explaining the thing. What is two-way data binding, you ask? 1) It is rad. 2) It allows the model and the view to be constantly talking to each other – when a user makes a change, it goes right into the model, and when the model changes, that is reflected in the view. 

This is how you feel right now, but it totally gets awesomer.

If you think back to the old restaurant metaphor, where you’re at a restaurant, and you’re ordering up some delicious serving of data, and your controller says, “Oui. One moment please,” then brings your request to the kitchen, where they get the data out of the walk-in, and they make it look nice, and then the controller returns to your table and says, “Et voila!” Every time you send that controller to the kitchen and back, your entire page reloads. You have an entirely new plate.

Now imagine if you didn’t have to wait for that trip back and forth. Imagine you can still order (add/retrieve some data to/from the walk-in) without sending someone alllll the way to the kitchen and back. Imagine you could order, and the contents of your plate would simply change, right there in front of you.

DO YOU KNOW WHAT THIS MEANS?!?!?! Do you see it? I can’t even – I mean – do you know what it means – I mean – omg –

What it means is this:

TWO-WAY DATA BINDING IS LIKE EATING IN THE DINING HALL AT HOGWARTS! 


This is me when I realized.

You tell your plate that you want some bacon mac & cheese (would that I were at Hogwarts right now…), and the house elves just magic it onto your plate right there. You don’t need to reload the page (of your app – in the non-Hogwarts context). You’ve got house elves.

Dobby is most pleased to be serving the users, he is.








No comments:

Post a Comment