new Class(uid){Class}
Name | Type | Description |
---|---|---|
uid |
String | The uid for this class |
Example
// 'blt5d4sample2633b' is a dummy Application API key
var cls = Built.App('blt5d4sample2633b').Class('project'); // person is a class uid.
Members
-
staticClass.Object
-
Represents an Object of a class
Example
// 'blt5d4sample2633b' is a dummy Application API key var object = Built.App('blt5d4sample2633b').Class('project').Object();
-
staticClass.Query
-
Represents a Query on a 'Class' which can be executed to retrieve objects that pass the query condition
Example
// 'blt5d4sample2633b' is a dummy Application API key var object = Built.App('blt5d4sample2633b').Class('project').Query();
Methods
-
staticClass.off(event, callback){Class}
realtime.js, line 1839 -
[Only avaliable with realtime plugin]
This function unregisters one or all event listener(s) from Class constructor.Name Type Description event
String The event whose listener needs to be unregistered [Optional] callback
function The callback function used while registering [Optional] Throws:
-
new Error('Callback function to be removed is missing')
-
new Error('Event name is missing');
Example
// 'blt5d4sample2633b' is a dummy Application API key // app.Class returns a 'Class' constructor var app = Built.App('blt5d4sample2633b').enableRealtime(); var Class = app.Class; function cb(classObj){ console.log(classObj.toJSON()); } // Sets up a listener for delete event Class.on('delete',cb); // Sets up a listener for broadcast event Class.on('broadcast',cb); // Specifically removes the delete listener Class.off('delete',cb); // Removes all listeners on Person Class.off(); // Removes all callbacks attached for delete event on this resource Class.off('delete'); // Throws "Event name is missing" Class.off(cb)
-
-
staticClass.on(event, callback){Class}
realtime.js, line 1224 -
[Only avaliable with realtime plugin]
This function registers an event listener on Class constructor.Given below is the list of supported events.
- Create
- Update
- Delete
- Broadcast
The 'create' event is triggered when a new class is created in this application. Registered callback is invoked with the created class data.
Update event is triggered when any class in this application is modified. Registered callback is invoked with the updated class data.
Delete event is triggered when any class in this application is deleted. Registered callback is invoked with the deleted class data.
Broadcast event is triggered when a message is broadcast for all classes belonging to this application. Registered callback is invoked with the broadcast message.
Name Type Description event
String The event on which the listener should be registered callback
function The callback function to be invoked on event trigger Example
// 'blt5d4sample2633b' is a dummy Application API key // app.Class returns a 'Class' constructor var app = Built.App('blt5d4sample2633b').enableRealtime(); var ClsCons = app.Class; ClsCons.on('create', function(classObj) { // newly created class console.log(classObj.toJSON()) }); ClsCons.on('update', function(classObj) { // updated class console.log(classObj.toJSON()) }); ClsCons.on('delete', function(data) { // deleted class data console.log(data) }); ClsCons.on('broadcast', function(message) { // The message broadcasted for all classes of this application });
-
getHeaders(){object}
class.js, line 147 -
Gets the headers of a class
Example
// 'blt5d4sample2633b' is a dummy Application API key var cls = Built.App('blt5d4sample2633b').Class('project'); var obj = cls.getHeaders();
-
getSchema(){Promise.<Array>}
class.js, line 172 -
Gets the schema of a class
Example
// 'blt5d4sample2633b' is a dummy Application API key var cls = Built.App('blt5d4sample2633b').Class('project'); cls.getSchema() .then(function(schema){ // schema is an array of fields })
-
off(event, callback){Class}
realtime.js, line 1877 -
[Only avaliable with realtime plugin]
This function unregisters one or all event listener(s) from Class instance.Name Type Description event
String The event whose listener needs to be unregistered [Optional] callback
function The callback function used while registering [Optional] Throws:
-
new Error('Callback function to be removed is missing')
-
new Error('Event name is missing');
Example
// 'blt5d4sample2633b' is a dummy Application API key // app.Class('class_name') returns an instance of that class // 'blt111sample2211r' is uid of an object on Built.io Backend var app = Built.App('blt5d4sample2633b').enableRealtime(); var person = app.Class('person'); function cb(personCls){ console.log(personCls.toJSON()); } // Sets up a listener for delete event person.on('delete',cb); // Sets up a listener for broadcast event person.on('broadcast',cb); // Specifically removes the delete listener person.off('delete',cb); // Removes all listeners on Person person.off(); // Removes all callbacks attached for delete event on this resource person.off('delete'); // Throws "Event name is missing" person.off(cb)
-
-
on(event, callback){Class}
realtime.js, line 1275 -
[Only avaliable with realtime plugin]
This function registers an event listener on Class instanceGiven below is the list of supported events.
- Update
- Delete
- Broadcast
Update event is triggered when the schema and/or the ACL of this class is modified. Registered callback is invoked with the updated class data.
Delete event is triggered when this class is deleted. Registered callback is invoked with the deleted class data.
Broadcast event is triggered when a message is broadcasted over the class instance. Registered callback is invoked with the broadcast message.
Name Type Description event
String The event on which the listener needs to be registered callback
function The callback function to be invoked on event trigger Throws:
new Error("Uid not found");Example
// 'blt5d4sample2633b' is a dummy Application API key var app = Built.App('blt5d4sample2633b').enableRealtime(); var Person = app.Class('Person'); Person.on('update', function(classObj) { // updated class console.log(classObj.toJSON()) }); Person.on('delete', function(data) { // deleted class console.log(data) }); Person.on('broadcast', function(message) { // The message broadcasted over this class });