background preloader

Intégration / libraries

Facebook Twitter

Powerful, Easy, Automatic. Backbone, deux ans après. Backbone fut une des premières librairies à offrir une structure aux applications JavaScript.

Backbone, deux ans après

Avec le succès qu’on lui connaît — trello , airbnb , linkedin . Cet article se propose de synthétiser l’expérience de deux ans de développements à ses côtés — mauvais jours inclus — d’identifier des bonnes pratiques et d’entrevoir la suite de l’aventure. Plus simple, tu meurs Backbone repose sur le pattern observeur de Smalltalk : les modèles stockent les données et émettent des évènements auxquels les vues s’abonnent — modification d’un attribut, réception d’une requête serveur, erreur de validation, etc. Les vues s’abonnent également aux évènements de l’interface — clic, saisie, etc. Backbone canalise la puissance des deux célèbres librairies $ et _ , auxquelles il ajoute peu, en définitive ( une liste d’évènements et une interface restful ). Simpliste, peut-être. Node.js Events and EventEmitter. One of the reasons for Node.js’ high speed is the fact that it is coded around events.

Node.js Events and EventEmitter

Instead of reading all the files necessary with every request (like PHP), with Node you just start your server, initiate most of the variables, declare your functions and then just wait for an event to occur. While Node.js has some useful built-in events, like the request event, wouldn’t it be useful to be able to create our own events and be able to trigger them ourselves? That’s what I’m going to talk about in this article. First I will show you how normal events are emitted.

As event I will take the example that when a person enters a shop, a bell may ring to show his presence. First we load the events module, which is part of the Node.js core. Now the interesting things are coming. This isn’t that interesting, could just have called that one function if we wanted the bell to ring. We could also have done this, for example: We can also use functions with arguments as listeners:

Derby. MVC framework making it easy to write realtime, collaborative applications that run in both Node.js and browsers. hello.js var app = require('derby').createApp(module); // Add template for rendering HTML and model <- -> view bindingsapp.view.make('Body', 'Holler: <input value="{hello.message}"><h1>{hello.message}</h1>'); // Add a route, which can render in the browser as well as serverapp.get('/', function(page, model) { // Specify data to sync model.subscribe('hello.message', function() { page.render(); });}); server.js hello.coffee app = require('derby').createApp(module) # Add template for rendering HTML and model <- -> view bindingsapp.view.make 'Body', 'Holler: <input value="{hello.message}"><h1>{hello.message}</h1>' # Add a route, which can render in the browser as well as serverapp.get '/', (page, model) -> # Specify data to sync model.subscribe 'hello.message', -> page.render()

Derby

CPU Profiling with Nodetime. By Dmitri Melikyan on 18 May 2012 One of the reasons for slow load times is inefficient code, which uses a lot of CPU making everything else wait. This is especially painful in Node.js due to its single threaded model. First signes of the problem are high CPU times of requests, which is easily observable in Nodetime, where CPU times are provided for each request sample. Although, machine load can also indicate a problem. The logical next step is to locate what exactly blocks CPU and where is that function in the code. V8 engine, on which Node.js is built, has a built-in sampling CPU profiler. To run the profiler manually a few things must be done. d8 should be compiled separately and Node application should be started with --prof option. Nodetime makes it increadably easy to use V8's CPU profiler.

We see that functions test1 and test2 were found pretty often on CPU. Checkout how to install and use Nodetime here . The Node Toolbox - Node.js happiness. Jaredhanson/passport - GitHub. Redback - A high-level Redis library for Node.JS. Marak squires: async.js - asynchronous co...