Diplomovka


Minimongo

https://github.com/meteor/meteor/tree/devel/packages/minimongo

Reimplementation - in-memory non-persistent JavaScript database, inside web browser, MongoDB API

Mongo features (mirrored na minimongu)

Naviac oproti Mongu


Meteor API

https://docs.meteor.com/

Core

  • https://docs.meteor.com/api/core.html
  • isServer, isClient, isCordova, ...
  • startup (funkcia na zbehnutie po starte- u klienta DOM ready)
  • wrapAsync(func, [context]) - asynchronne, v inom vlakne (u klienta stale)
  • defer(f) - funkcia asynchronne nech sa psuti
  • Meteor.absoluteUrl([path], [options]), Meteor.release()
  • Meteor.settings - konfiguracie konkretneho nasadenia

Publish a subscribe

  • https://docs.meteor.com/api/pubsub.html , niektore veci naviac/ine http://www.meteorpedia.com/read/Understanding_Meteor_Publish_and_Subscribe
  • publish(name of collection, func)
    • dva sposoby publish - prva cast je vyborna, od polovice nezaujimave - http://richsilv.github.io/meteor/meteor-low-level-publications/
      • publish s collection -> cursor klientovi(cez DDP neda sa, teda dokumenty? (add, chang..), ale na klientovi do minimonga a tam cursor), meteor sa stara o poslanie, observe a ready
      • publish na nizsej urovni, ala DDP, to iste pride (v linku vyssie popisane). Je to aj na ich stranke pri tom, ale ala "what?" :D
    • added, changed, removed (collection, id, +fields), ready, erro, stop, onStop, connection (bude dalej)
  • subscribe(name, argumenty (ejson moze byt), callbacks) - vracia handle s stop a ready
    • client uklada do minimongo kolekcii s menom ake bolo v add/change/remove DDP spravach, t.j. nazov mongo kolekcie na servri
    • merge-ovanie dokumentov ak z roznych publikacii a ine fieldy - fakt ako na ich stranke (len top level); dole-> https://dweldon.silvrback.com/common-mistakes
    • handle ma stop, ready, subsriptionId
    • ak v reactive (autorune napr) subscription spravena a zmenena napr - stop automaticky sa deje

Methods

  • https://docs.meteor.com/api/methods.html
  • Meteor.methods(methods) - deklaracia, zoznam vnutri. Return EJSON-able value.
  • database mutators (insert, update, remove) are implemented as methods
  • Ak mame stub - Metody bezia na sevri aj klientovi (!) potom pri volani.
  • Ak sa zavola, disconnectne, tak sa opat metoda zavola aj po reconnectnuti.
  • Inside your method invocation, this is bound to a method invocation object
    • isSimulation: boolean, ci klient (true tam)
    • unblock: when called, allows the next method from this client to begin running
    • userId (vrati id), setUserId: a function that associates the current client with a user
    • connection: on the server, the connection this method call was received on
  • new Meteor.Error(error, [reason], [details]) - exception ktora bude poslana do klienta zo servra
  • Meteor.call(name, [arg1, arg2...], [asyncCallback])
    • posledny argument - function (error, result) { ... } - ak je, metoda asynchronne a potom callback s onymi (err, res), ale az po zapisoch servera do lokalnej cache. Bez tohto metoda ide synchronne.
    • cele bloky kopirujem, zlozite sa mi to zda
    • On the client, if you do not pass a callback and you are not inside a stub, call will return undefined , and you will have no way to get the return value of the method. That is because the client doesn’t have fibers, so there is not actually any way it can block on the remote execution of a method.
    • Finally, if you are inside a stub on the client and call another method, the other method is not executed (no RPC is generated, nothing “real” happens). If that other method has a stub, that stub stands in for the method and is executed. The method call’s return value is the return value of the stub function. The client has no problem executing a stub synchronously, and that is why it’s okay for the client to use the synchronous Meteor.call form from inside a method body, as described earlier.
  • Meteor.apply(name, args, [options], [asyncCallback]) - to iste, len array argumentov
    • wait - (Client) If true, don't send this method until all previous method calls have completed, and don't send any subsequent method calls until this one is completed.
    • onResultReceived - (Client) ak nechceme cakat napr za asyncCallback
    • noRetry - (Client) if true, don't send this method again on reload, callback an error
  • DDPRateLimiter - rate limiting for methods and subscriptions
    • default - limits login attempts, new user creation, and password resets to 5 attempts every 10 seconds per connection
    • .addRule, .removeRule, .setErrorMessage (serverovske veci myslim, neriesim...)

Check

  • https://docs.meteor.com/api/check.html
  • lightweight package
  • check(roomId, String);
  • Meteor.Error(400, "Match Failed") - taky fail pride na klienta (ak...)
  • test na strukturu - .test will return true for {foo: 1, bar: "hello"} or similar: Match.test(value, {foo: Match.Integer, bar: String});
  • match patterny (tam su...)

Connection

Sesion

  • https://docs.meteor.com/api/session.html
  • global object on the client that you can use to store an arbitrary set of key-value pairs
  • reactive. If you call Session.get("currentList") from inside a template, the template will automatically be rerendered whenever Session.set("currentList", x) is called.
  • get, set, setDefault
  • Session.equals(key, value) - lepsie ako get a porovnanie, lebo reaktivne : It triggers fewer invalidations (template redraws), making your program more efficient.

Collections

  • https://docs.meteor.com/api/collections.html
  • new Mongo.Collection(name, [options]) - v options: connection, idGeneration, transformers..
    • Each document is a EJSON object
    • _id ma vzdy
    • The function returns an object with methods to insert documents in the collection, update their properties, and remove them, and to find the documents in the collection that match arbitrary criteria. The way these methods work is compatible with the popular Mongo database API. The same database API works on both the client and the server
    • Ak sa da meno, klasika spravanie, persistent,
    • If you pass null as the name, then you’re creating a local collection. It’s not synchronized anywhere; it’s just a local scratchpad that supports Mongo-style find, insert, update, and remove operations. (On both the client and the server, this scratchpad is implemented using Minimongo.)
    • transform - Transform functions must return an object and they may not change the value of the document’s _id field (viac v linku) + http://stackoverflow.com/questions/18093560/meteor-collection-transform-is-it-done-on-the-server-or-on-the-client-or-it-de
    • Zaujimava poznamka: Minimongo doesn’t currently have indexes. It’s rare for this to be an issue, since it’s unusual for a client to have enough data that an index is worthwhile.
  • Mongo.Collection#find([selector], [options])
    • find returns a cursor. It does not immediately access the database or return documents. Cursors provide fetch to return all matching documents, map and forEach to iterate over all matching documents, and observe and observeChanges to register callbacks when the set of matching documents changes
    • cursors are reactive - On the client, the first time you retrieve a cursor’s documents with fetch, map, or forEach inside a reactive computation (eg, a template or autorun), Meteor will register a dependency on the underlying data. Any change to the collection that changes the documents in a cursor will trigger a recomputation. (disable this - {reactive: false} as an option to find)
    • use of fields allows for more fine-grained reactivity
  • Mongo.Collection#findOne([selector], [options])
  • Mongo.Collection#insert(doc, [callback])
    • Returns its unique _id.
    • optimistic ui - consistent id (seed) - https://guide.meteor.com/methods.html#consistent-id-generation
    • On the server, if you don’t provide a callback, then insert blocks. If you do provide a callback, insert still returns the ID immediately.
    • On the client, insert never blocks. If you do not provide a callback and the insert fails on the server, then Meteor will log a warning to the console. If you provide a callback, Meteor will call that function with error and result arguments. (_id je v resulte)
  • Poznánmka: Trusted code includes server code and method code. Untrusted code includes client-side code such as event handlers and a browser’s JavaScript console. http://stackoverflow.com/questions/15464507/understanding-not-permitted-untrusted-code-may-only-update-documents-by-id-m
  • Mongo.Collection#update(selector, modifier, [options], [callback])
  • Mongo.Collection#upsert(selector, modifier, [options], [callback]) - lol, to je divne, mutant z insert a update
  • Mongo.Collection#remove(selector, [callback])
    • funguje ako predchadzajuce
  • Mongo.Collection#allow(options)
    • When a client calls insert, update, or remove on a collection, the collection’s allow and deny callbacks are called on the server to determine if the write should be allowed. If at least one allow callback allows the write, and no deny callbacks deny the write, then the write is allowed to proceed
  • deny podobne, to su serverovske starosti myslim
  • Mongo.Collection#rawCollection()
  • Mongo.Collection#rawDatabase()

Random


Správy (prichádzajúce)

     DDPClient ddp = new DDPClient("localhost", 3000);
     DDPTestClientObserver obs = new DDPTestClientObserver();
     ddp.addObserver(obs);
     ddp.connect();

MESSAGE full ----- {msg=connected, session=E7o2PpLdfJ8Yrd72w}

     ddp.subscribe("tasks", new Object[]{});

MESSAGE full ----- {msg=added, collection=tasks, id=qFYusq6AKjCtwatNF, fields={text=Novy task moj, createdAt={$date=1.476038201034E12}, owner=EBTiuAASWGZ8fKDSY, username=jamal, checked=false}} MESSAGE full ----- {msg=added, collection=tasks, id=xvPmZ42g4PBYBDdEX, fields={text=Ineho dokument, createdAt={$date=1.47603824959E12}, owner=8PnMLwaoH6oASLJnK, username=inydakto, checked=false}} MESSAGE full ----- {msg=added, collection=tasks, id=5stYLuq5tqNhHzyqe, fields={text=dalsi task, nech je viac, createdAt={$date=1.477096402904E12}, owner=EBTiuAASWGZ8fKDSY, username=jamal}} MESSAGE full ----- {msg=added, collection=tasks, id=D3oBSM48aSDs2e4t8, fields={text=Este poskusaj veci, createdAt={$date=1.47712776129E12}, owner=iF2iZeQCAbR97BZcs, username=testik}} MESSAGE full ----- {msg=added, collection=tasks, id=Qp8X3uMdFbM5NtBAL, fields={text=Prihlas sa sem..., createdAt={$date=1.477128230746E12}, owner=iF2iZeQCAbR97BZcs, username=testik}} MESSAGE full ----- {msg=added, collection=tasks, id=YBFLeWoxuXXooMun7, fields={text=Testikove todo, createdAt={$date=1.477128267027E12}, owner=iF2iZeQCAbR97BZcs, username=testik}} MESSAGE full ----- {msg=added, collection=tasks, id=ZF9CnAvhdRvwn4ntF, fields={text=A PRIDAM ESTE DACO, CI POJDE DO JAVY, createdAt={$date=1.477136064696E12}, owner=iF2iZeQCAbR97BZcs, username=testik}} MESSAGE full ----- {msg=added, collection=tasks, id=z7GRL7nnPMnduRuhK, fields={text=Pridany cez Javuuuuu, createdAt={$date=1.477178774319E12}, owner=iF2iZeQCAbR97BZcs, username=testik}} MESSAGE full ----- {msg=ready, subs=[1]}

     ddp.ping("sprava?", new DDPListener());

MESSAGE full ----- {msg=pong, id=sprava?}

     Object[] methodArgs = new Object[1];
     UsernameAuth auth = new UsernameAuth("testik", "testik");
     methodArgs[0] = auth;
     int methodId = ddp.call("login", methodArgs, obs);

MESSAGE full ----- {msg=added, collection=users, id=iF2iZeQCAbR97BZcs, fields={username=testik}} MESSAGE full ----- {msg=ready, subs=[1]} MESSAGE full ----- {msg=result, result={id=iF2iZeQCAbR97BZcs, token=FI9-eg5mnulBqWd5NTANnG0S2ICeOpGD9yKDvFw5zaz, tokenExpires={$date=1.485079644782E12}}, id=2} MESSAGE full ----- {msg=updated, methods=[2]}

     methodArgs = new Object[1];
     methodArgs[0] = "Pridany cez Javuuuuu";
     ddp.call("tasks.insert", methodArgs);

MESSAGE full ----- {msg=result, id=3} MESSAGE full ----- {msg=added, collection=tasks, id=YvjckL2Jynpmux2ki, fields={text=Pridany cez Javuuuuu, createdAt={$date=1.477303644984E12}, owner=iF2iZeQCAbR97BZcs, username=testik}} MESSAGE full ----- {msg=updated, methods=[3]}

     Server pinguje. Kazdych zhruba 10 sekund?

MESSAGE full ----- {msg=ping} MESSAGE full ----- {msg=ping} ...

     Pridal som cez browser dokument (metodu volal niekto iny, nie ja).

MESSAGE full ----- {msg=added, collection=tasks, id=PpwXmy3zCx7WohXMj, fields={text=Bude daco ze je ready ked len tak daco pride?, createdAt={$date=1.477304104862E12}, owner=iF2iZeQCAbR97BZcs, username=testik}}

     Vypol som server.

MESSAGE full ----- {msg=closed, reason=, code=1006, remote=true}


Dodatky




Štruktúra meteoru, nástrely

https://camo.githubusercontent.com/dba00266cf8c281e32e03a52a246068e37884412/687474703a2f2f626c6f6e6b2e636f2e73332e616d617a6f6e6177732e636f6d2f696d672f72656163746976652d6d6574656f722d64617461322e6a7067

Green Marinee theme adapted by David Gilbert, powered by PmWiki