Skip to content
Hai Phan edited this page Jun 25, 2018 · 10 revisions

Session Support

If the model object defines the methods "onConnect" and "onDisconnect", they will be called automatically when a client connects and when it disconnects. The special property session holds an object that is visible only to the current client.

class MyModel {
  async signIn(email, pass) {
    this.session.userId = await findUser(email, pass);
  }
  updatePhone(phone) {
    updateUser({userId: this.session.userId, phone: phone});
  }
}

Private Properties

By default, any property that begins with the underscore character are private and not seen by clients (cannot be subscribed to). To change this behavior:

require("push-model").options.excludeProperty = function(obj, prop) {
  //return true to exclude this property
  //return typeof prop == "string" && prop.startsWith("_")
}

Splice Patch

This module uses the jsonpatch-observe library, which can generate a non-standard "splice" patch for array changes. Without this, array changes have to be represented as a series of single-element add/removes, which is quite inefficient. The splice patch is enabled by default, make sure your client can handle this patch. To disable this feature, do:

require("push-model").options.enableSplice = false;
Clone this wiki locally