BackboneConf 2013

Cómo utiliza LinkedIn los controladores en sus aplicaciones Backbone

Asa Kusuma  · 

Presentación

HTML (pincha para descargar)

Vídeo

Transcripción

Extracto de la transcripción automática del vídeo realizada por YouTube.

as Adam said my name is a sec assume from LinkedIn and today I just want to talk about a few ways you can become a control rig in a good way with a couple of tools including promises and controllers yeah so today I work at LinkedIn I'm a mobile web developer

outside of when development some added a quarter yeah i've been at linkedin for a pouch almost a year now and i graduate from school over a year ago so these are my my favorite foot of me running JavaScript since he had been doing it for quite some time

yeah let's talk about mobile web and LinkedIn so in 2011 we launched a wasn't our personal web experience it was the first backbone app that LinkedIn had in production and then about later 2000 photo we decided how you want to give our background that

they face lift so no we just want to change the views and change how the app feel so that should be easy right fortunately that was not exactly the case and so today I want to talk a little bit about the learnings we had from refactoring our web experience

so after we launched this new my web experience we kind of got in a room together and said okay what can we do to improve the infrastructure of our development environment and how we going to prove writing code and how we make our site faster so we want to

just improve our site not making anything about the products but just about improving the technology so we form the team to call it team Austin and our slogan was the wild rest Wild West refined so what we kind of like to characterize our situation was we

had a wild Western Han so we expanded really fast we launched on the really cool products but we needed to step back and kind of bring some infrastructure to a website that we had built so a couple of things that characterize and we call this quad weft so

Brian did a really awesome job of talking yesterday about controllers and routers and so when things he talked about which I went to echo was this concept of routers being super bloated if you don't kind of properly funnel code right and so this is a picture

of what our router one of our routers look like this is actually after a major refactor so you can see we had actually implemented AMD at this point and there's a big in md plus the beginning but it was just like this shoe super huge unwieldy thing and

it wasn't very fun to work with another thing we found was at our control flow it was less than ideal so we would often have to asynchronous operations that had nothing to do with each other besides the fact that after they were both done we needed to

do something else and so instead of doing some parallel we would often through this up in series this is not good and then another thing we found we had was we definitely had that much abstraction and so we would have you where we were doing that manipulation

and also caching so if you wanted to change the visual components you also had to know about our caching layer which was also not a good thing so two things one you know where are actively taming our Wild West so we're not done yet we're in the process

and so today I just want to share with you a few of the things that were actively working on some of the some of which are in production and some of which are not the other thing is that we are actively optimizing for mobile web so we have some other back

those stacks on our site I'm not gonna be talking about those mostly focusing on mobile so we have a feeling that we aren't the only ones for both of these things with respect to both developing for mobile and with respect to actively improving our

backbone experience so process that the heart of promises is we're talking mostly about ways of simplifying and abstracting asynchronous backbone and so the main concept here is that we want to create some kind of object that we can use to given in operation

that promises a future result have a handle that operation so like I said the heart of this is abstraction so abstract ins are easier to control this is kind of a theme of this one way easier to wheel so profitez basically allow us to reason and think and

manipulate a stiffness operations in a synchronous manner this is huge for readability and maintainability so a couple details about promises so there are lots of ways you can implement promises I'm we talking today mostly about the a-plus spec which is

a set API for interacting with promises there are lots of libraries that implement the A+ effect I mean you're talking mostly about to you today cuz that's what we use but you can use any promise library like when and then the main points our main

AAP I to a promise is the Venn function so our event function allows you to attach a handler to your promise objects so the cool thing about promises that backbone and jQuery already use them so any are publicly most backbone asynchronous operations return

a promise that you could use as do many jk asynchronous operations so they were turned a JQ an xhr which is a promise topic that typically represents an xhr operation so why are primes is cool probably cool because if you have let's say a call back Shane

you can easily string them together any more readable fashion so here we have a safe three operations we want to do in series typically we'd have a call back Shane but instead of you can flatten that into one lap clock so pretty much to work with so as

I kind of mentioned earlier we had this issue where we would have two operations that really can be done in parallel and instead we're done in series and so typically if you want to make your code more efficient a lot of times you have to add more complexity

to your code and so we had both complex code and inefficiency which was definitely a hundred so this is a natural chunk of code from our repo about twenty six months ago to change some names but essential food is in production so if you see there's free

call bags so first we do a page animation slide the page over then you go fetch some data and then we actually display net down so you can actually do this page our data fetching and animation at the same time and so this is kind of what this looks like after

so we use q but you can use any promise library most promise loggers have an all function which takes two promises and it kind of merges them so it returns a promise that will be completed when both promises were solved so we multiply the Shiva page function

to return a promise and then like I said earlier fetching back when fetching by default returns a promise so you pipe those two in and you get out if you promise which you can attach a handle or call back to so notice right now I'm using it on this function

of the call back that's for readability say for the presentation in real life you would want to use a member function so it's way more readable and you can actually test it so that last slide we discovered it makes it a lot easier if you put that in

a controller it's a like Brian this round earlier those are pretty awesome and we kind of went back to this this idea of praying the sea back in and they stink and using controllers so backbone is not a framework we've talked a lot about that and it's

really a library for building a framework so cool thing that backbone is it gives you the developer lots of power and with that power comes responsibility and that responsibility is to build the framework that you want to use and we found out that if you don't

really build that framework that each developer kind of builds his own framework which can be a problem when you have lots of developers working on the same backbone so one of my favorite concepts that an exec asst talks about is this concept that everything

[ ... ]

Nota: se han omitido las otras 3.858 palabras de la transcripción completa para cumplir con las normas de «uso razonable» de YouTube.