Meteor
-
Upload
giuseppe-frattura -
Category
Engineering
-
view
129 -
download
1
Transcript of Meteor
Meteor
Full stack platform to create of application web and mobile,
using only Javascript.
Includes UI library: Blaze, but you can use Angular 1/2 or React.
Help create reactive application, includes a build tool and many packages.
Meteor use data on the wire, server doesn’t send HTML but just data, and client
render it.
What?
What? (2)
●Mongo DB
●NodeJS
●Blaze/Angular/
ReactMeteor “contains” all the Stack ● Server part with node js with mongoDB for data;● In between, translation side, with shadow dom create page and inject script
and style and send them to client;● Client side connected with server ddp (distribuited data protocol ) protocol;
Directory structure
● client;● server;● libs, include, ...
Meteor scans all HTML files in the application and concatenates them together.
Concatenation means merging the content of all HTML, HEAD and BODY tags
found inside these HTML files together.
Meteor includes Packages for test, Mocha and Jasmine
Atmosphere site contains all the public Meteor Packages
How it works?
Two package are installed by default Insecure e Autopublish. Useful for rapid prototyping.
With Insecure is possible execute CRUD operation without any permission;
Autopublish send all data on DB to the client without any filter;
To remove:
meteor remove insecure / meteor remove autopublish
Autopublish example
Without the autopublish package, we will have to specify explicitly what the
server sends to the client. The functions in Meteor that do this are Meteor.publish
and $scope.subscribe.
Calling Meteor.publish on the server registers a publication named "tasks".
When $scope.subscribe is called on the client with the publication name, the client
subscribes to all the data from that publication, which in this case is all of the tasks
in the database.
MongoDB - Minimongo
Meteor speed up comunication with mongoDB using a library minimongo
How it works
Every Meteor client includes an in-memory database cache. To manage the client
cache, the server publishes sets of JSON documents, and the client subscribes to
these sets. As documents in a set change, the server patches each client's cache
automatically. This is Latency Compensation o Optimistic UI.
MongoDB is the only supported dbms.
Optimistic UI
When you call a method on the client using Meteor.call, two things happen in
parallel:
1. The client sends a request to the server to run the method in a secure
environment, just like an AJAX request would work
2. A simulation of the method runs directly on the client to attempt to predict the
outcome of the server call using the available information
Optimistic UIIn the Simple-todos exemple (Demo) a newly created task actually appears on the
screen before the result comes back from the server.
If the result from the server comes back and is consistent with the simulation on
the client, everything remains as is. If the result on the server is different from the
result of the simulation on the client, the UI is patched to reflect the actual state of
the server.
App mobile
With Meteor is easy to create app for iOS (App Store), and application for Android (Google Play).
How?Meteor compile application with Apache Cordova so is not necessary write code twice. This hybrid App contains web code and native code inside.
For iOS are available dedicate library for user interface to obtain better performance
Commands
Meteor.isServer can be used to limit where code runs, but it does not prevent code
from being sent to the client. Any sensitive code that you don’t want served to the
client, such as code containing passwords or authentication mechanisms, should
be kept in the server directory.
Meteor.isDevelopment Boolean variable. True if running in development
environment.
Meteor.isProduction Boolean variable. True if running in production environment.
Meteor.startup(func) Run code when a client or a server starts.
On a server, the function will run as soon as the server process is finished starting.
On a client, the function will run as soon as the DOM is ready.
Code wrapped in Meteor.startup always runs after all app files have loaded.
Commands
Example
// On server startup, if the database is empty, create some initial data.
if (Meteor.isServer) { Meteor.startup(function () { if (Rooms.find().count() === 0) { Rooms.insert({name: "Initial room"}); } });}
http://www.hiddenbrains.com/articles/wp-content/uploads/2016/05/meteorJS-or-mean-stack-which-one-works-for-you-twitter-min.png
Meteor works with ES6 and AMDhttps://forums.meteor.com/t/new-package-rocket-module-to-provide-cjs-amd-es6-modules-for-meteor-packages-with-shared-npm-dependencies/4620
https://twitter.com/dandv/status/578693448196231168
Test
meteor test --driver-package practicalmeteor:mocha