ng-conf 2014

ORM para AngularJS

Dean Sofer  · 


HTML (pincha para descargar)



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

Vince the the demo guys to let me give a quick mini talk after this so if you guys want to keep talking you can or if you guys want to sit in on it it's on an angularjs ORM architecture I developed but if you guys wander in and out that's totally cool

I won't be offended anyways so to introduce myself my name is Dean Sofer I go by Pro loser online if you guys have seen me I founded angular UI and I haven't been really active lately because I've been working at my company on this architecture

and I really wanted to give a talk on this but they had so many awesome speakers I managed to convince them at the last minute though like yesterday to let me come up here so uh although it's called thank you it's called angular or RM for lack of a

better title but it's actually a bunch of different topics on scalable application design and what we've developed at my company so I'm kind of an asshole you can check me out on github prove Oh / pro loser and these are the topics I want to cover

such as like people have to deal with too much scope clutter developing a relational model system which is what ou R M is for organizing your packages so you can actually make your application get hundreds or thousands of files without crippling yourself hopefully

live applications connected to the back end from sockets so multiple parts of your application stay up to date real-time and event management so dealing with all that things and ponies but I probably won't get out to everything because it's a lot of

stuff and I'll try and cut it short so the angular or M I developed I used four items and one thing I want to say is that these are patterns and prototypes it's not a library these are ideas to give you something to take home and try imply to your

own solution but might give you some new thoughts so I use CoffeeScript ui-router which is the coolest router out there the only you only got two but if you haven't checked it out so CoffeeScript if you know about it's interesting syntax if some people

ask me should I pick it up and I tell them do you want classes and JavaScript if so and were you considering picking up CoffeeScript then yes otherwise you might not want to bother unless you got a pro on your team already ui-router has got nested views named

views state transition state management tokens with that you can specify regular expression for and a bunch of other awesome features my company uses sockets which are pretty simple and we use this awesome library called bacon j/s which is a stream and event

management library and it's to simplify the socket process because pretty much a socket is just gonna be thousands or hundreds of messages coming in and a lot of people spend a lot of time wiring it in all over the application anyways so quick intro for

people who don't know CoffeeScript I use CoffeeScript in these demos to make it more concise and show you more useful code if you see in parentheses with an arrow that's a function if you see an @ sign that's the this dot and occasionally leave

out parentheses around functions and you don't need curly braces so that's just it to the intro to CoffeeScript so let's build an app first time most people play with angular you first thing they do is put a button on the page and then they put

a piece of HTML on the page and the button is usually toggled by some simple scope variable and the section of the page is open and closed by some simple scope variable and after a couple of hours of playing with it you've got an insane mess of scope variables

which are pretty much States and after working with it for a month you might have hundreds of scope variables or no rhyme or reason or cross communication conflicts with your co-workers where somebody uses one variable name and somebody else uses another and

nesting hierarchy causes variables to get redefined and it's just a nightmare so the policy behind this ORM architecture is to remove as much code as possible from the controller layer and move it into a object layer so this is usually what your controller

looks like you have methods on the controller scope dot save you actually subscribe to events you distribute managed collections like you query data you update data you push data back out but all those all that codes done in the controller so this is models

on crack this is CoffeeScript the class syntax you can see right here this is just simple CoffeeScript it just creates a function messes with its prototypes but you can wrap it in a factory you can wrap obviously any code in the factory the reason I used a

factory not a service is because the factory really doesn't mess with my objects it just kind of leaves them intact so I can define my classes wrap them in factories and now I have a base object which is a simple class and I can create a person object

and the person object extends the base object but I can use angular's dependency injection wrapped around my CoffeeScript to inject the different classes I've been defining throughout my app and then you can also do nifty little tricks with factories

since this is a class and you need to spin up instances of classes which we all know is called objects you can simply create a singleton by spinning up one instance and returning that instead of the class itself at the end of your factory so I defined an app

object that's like the point of entry for the entire ORM but I'll go into how these objects are related to each other not just extending each other so if you do put all this stuff together like you start managing save methods collection management

and all this stuff inside your object layer your controller becomes irrelevant the only thing I have to do is take this really powerful object layer maybe the app object or the person object and throw it on the scope and then my view does most of the work

[ ... ]

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