-
Notifications
You must be signed in to change notification settings - Fork 1
Other Features
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});
}
}
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("_")
}
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;