-
Notifications
You must be signed in to change notification settings - Fork 67
Custom Property Manager [v2]
Adrien Castex edited this page Apr 21, 2018
·
1 revision
A Property Manager
is an object instantiated for each resource in order to:
- list the properties of this resource
- get a specific property of this resource
- set a property to this resource
- remove a property of this resource
This object must be serializable in order to be saved with the architecture of the state of the server.
interface IPropertyManager
{
setProperty(name : string, value : ResourcePropertyValue, attributes : PropertyAttributes, callback : SimpleCallback) : void
getProperty(name : string, callback : Return2Callback<ResourcePropertyValue, PropertyAttributes>) : void
removeProperty(name : string, callback : SimpleCallback) : void
getProperties(callback : ReturnCallback<PropertyBag>, byCopy ?: boolean) : void
}
interface PropertyBag
{
[name : string] : {
value : ResourcePropertyValue
attributes ?: PropertyAttributes
}
}
You can instantiate a basic Property Manager
called LocalPropertyManager
. It will store the properties in memory (in an object variable called properties
of type PropertyBag
) and manage the list.
Here is its implementation (which can be used as an example):
class LocalPropertyManager implements IPropertyManager
{
properties : PropertyBag = { };
constructor(serializedData ?: any)
{
if(serializedData)
for(const name in serializedData)
this[name] = serializedData[name];
}
setProperty(name : string, value : ResourcePropertyValue, attributes : PropertyAttributes, callback : SimpleCallback) : void
{
this.properties[name] = {
value,
attributes
};
callback(null);
}
getProperty(name : string, callback : Return2Callback<ResourcePropertyValue, PropertyAttributes>) : void
{
const property = this.properties[name];
callback(property ? null : Errors.PropertyNotFound, property.value, property.attributes);
}
removeProperty(name : string, callback : SimpleCallback) : void
{
delete this.properties[name];
callback(null);
}
getProperties(callback : ReturnCallback<PropertyBag>, byCopy : boolean = false) : void
{
callback(null, byCopy ? this.properties : JSON.parse(JSON.stringify(this.properties)));
}
}
- Home
- Version 2
- Install
- Quick Start Guide
- Examples
- Concepts
- User concepts
- Server concepts
- Customizing
- Version 1 [Obsolete]
- Install
- Quick Start Guide
- Examples
- Features
- Resource concepts
- User concepts
- Server concepts
- Customizing
- Project