Archivi categoria: Real-Time Web

Object.observe()

Stiamo per dire addio ai vari framework mvc (Angular, Meteor, Dart ecc)?
Non ancora. Ma il nuovo metodo Object.observe() darà un grande impulso allo sviluppo di applicazione Web Real Time più compatte e veloci.
Uso il futuro perchè al momento questa tecnologia, che è una anticipazione di quello che ci porterà ES7, è supportata solamente da Chrome 36 e Opera 23, quindi oggi solo pochi fortunati si possono divertire!!!

Cosa fa Object.observe() ?

Questo metodo attacca ad un generico oggetto JS una callback che reagisce (viene invocata) a qualsiasi variazione avviene sull’oggetto stesso:

// definiamo un oggetto di nome user con due 
// proprietà: nome e anno_nascita

var user = {
  nome: 'Alessandro',
  anno_nascita: 1990
};

// collega una callback con observe()
// attenzione: changes è un array!!
Object.observe( obj,  function(changes) {
  console.log(changes);
});

user.nome = 'Alex'; 
// sulla console appare un messaggio che indica:
// la proprietà modificata, 
// il nome dell'oggetto, 
// il tipo di modifica, 
// il valore della proprietò prima della modifica
// [{name: 'nome', object: <user>, type: 'update', oldValue: 'Alessandro'}]

.observe reagisce a 6 tipi di variazione:

  • add
  • update
  • delete
  • reconfigure
  • set_prototype
  • prevent_extension

add, update e delete si riferiscono alla aggiunta, modifica ed eliminazione di proprietà dell’oggetto.

Quanto è veloce?

Da test effettuati risulta che rispetto all’utilizzo di AngularJS il metodo observe() è dal 20 a 40 volte più veloce!

Meteor è nella top ten di GitHub

meteor

Meteor è entrato nella lista dei 10 progetti più stellati di GitHub.

Ricordiamo i principi fondamentali di questo framework, citando il sito www.meteor.com:

Principles of Meteor

  • Data on the Wire. Meteor doesn’t send HTML over the network. The server sends data and lets the client render it.
  • One Language. Meteor lets you write both the client and the server parts of your application in JavaScript.
  • Database Everywhere. You can use the same methods to access your database from the client or the server.
  • Latency Compensation. On the client, Meteor prefetches data and simulates models to make it look like server method calls return instantly.
  • Full Stack Reactivity. In Meteor, realtime is the default. All layers, from database to template, update themselves automatically when necessary.
  • Embrace the Ecosystem. Meteor is open source and integrates with existing open source tools and frameworks.
  • Simplicity Equals Productivity. The best way to make something seem simple is to have it actually be simple. Meteor’s main functionality has clean, classically beautiful APIs.