https://www.meteor.com/前端
Meteor is an ultra-simple environment for building modern web applications.node
With Meteor you write apps:python
- in modern JavaScript
- that send data over the wire, rather than HTML
- using your choice of popular open-source libraries
名字是流星的意思,意味着助理開發者,快速開發應用。git
同時還有數據更新很快的含義, 服務器端更新數據後,會很快的同步到全部觀測此數據的全部客戶端軟件上。github
https://github.com/meteor/meteor/blob/devel/packages/ddp/DDP.mdweb
DDP is a protocol between a client and a server that supports two operations:npm
- Remote procedure calls by the client to the server.
- The client subscribing to a set of documents, and the server keeping the client informed about the contents of those documents as they change over time.
meteor應用框架靈魂是其定義的一套 DDP協議(Meteor's Distributed Data Protocol),後端
此協議的實現兩個功能:服務器
1) 客戶端能夠調用服務器端的方法, 即支持遠程調用, 一些後端的邏輯, 就能夠寫在前端, 打薄後端。app
2)客戶端能夠訂閱服務器端的數據,當服務器端管理的數據改變後,全部訂閱此數據的客戶端都會被通知。
數據變動以下圖, 客戶端發起請求,改變服務端數據, 數據改變後,通知客戶端更新數據。
minimongo負責客戶端數據的跟蹤,正常狀況會同服務器端的數據一致。
https://www.npmjs.com/package/ddp
A callback style DDP (Meteor's Distributed Data Protocol) node client, originally based alansikora's node-js_ddp-client and Meteor's python client. Uses a more callback style approach.
客戶端RPC 和 訂閱。
setTimeout(function () { /* * Call a Meteor Method */ ddpclient.call( 'deletePosts', // name of Meteor Method being called ['foo', 'bar'], // parameters to send to Meteor Method function (err, result) { // callback which returns the method call results console.log('called function, result: ' + result); }, function () { // callback which fires when server has finished console.log('updated'); // sending any updated documents as a result of console.log(ddpclient.collections.posts); // calling this method } ); }, 3000); /* * Subscribe to a Meteor Collection */ ddpclient.subscribe( 'posts', // name of Meteor Publish function to subscribe to [], // any parameters used by the Publish function function () { // callback when the subscription is complete console.log('posts complete:'); console.log(ddpclient.collections.posts); } ); /* * Observe a collection. */ var observer = ddpclient.observe("posts"); observer.added = function(id) { console.log("[ADDED] to " + observer.name + ": " + id); }; observer.changed = function(id, oldFields, clearedFields, newFields) { console.log("[CHANGED] in " + observer.name + ": " + id); console.log("[CHANGED] old field values: ", oldFields); console.log("[CHANGED] cleared fields: ", clearedFields); console.log("[CHANGED] new fields: ", newFields); }; observer.removed = function(id, oldValue) { console.log("[REMOVED] in " + observer.name + ": " + id); console.log("[REMOVED] previous value: ", oldValue); }; setTimeout(function() { observer.stop() }, 6000); });
https://www.npmjs.com/package/minimongo
本地存儲, mongo風格API
A client-side MongoDB implementation which supports basic queries, including some geospatial ones.
Uses code from Meteor.js minimongo package, reworked to support more geospatial queries and made npm+browserify friendly. It was forked in January 2014.
It is either IndexedDb backed (IndexedDb), WebSQL backed (WebSQLDb), Local storage backed (LocalStorageDb) or in memory only (MemoryDb).
// Require minimongo var minimongo = require("minimongo"); var LocalDb = minimongo.MemoryDb; // Create local db (in memory database with no backing) db = new LocalDb(); // Add a collection to the database db.addCollection("animals"); doc = { species: "dog", name: "Bingo" }; // Always use upsert for both inserts and modifies db.animals.upsert(doc, function() { // Success: // Query dog (with no query options beyond a selector) db.animals.findOne({ species:"dog" }, {}, function(res) { console.log("Dog's name is: " + res.name); }); });