Properties and Data
quip.apps.Record.getProperties
Function() => PropertySchema
Required static method on all classes registered using quip.apps.registerClass()
. This should return a "schema" of the properties that will be stored for this Record type, in the following format:
interface PropertySchema {
[key: string]: "string"|"number"|"boolean"|"object"|"array"|quip.apps.Record|listPropertyType
}
The value for each property should indicate the data type of the property being stored, and can either be one of a list of hard-coded primitive types, a Record constructor function (e.g. quip.apps.Record
, quip.apps.RichTextRecord
, or a Record subclass that the developer has defined), or a list type generated using quip.apps.RecordList.Type()
.
Example
static getProperties() {
return {
"header": CardRecord,
"cards": quip.apps.RecordList.Type(CardRecord),
"color": "string"
};
}
quip.apps.Record.getDefaultProperties
optional
Function() => { [prop: keyof SchemaProperties]: any }
Optional static method that returns default values for some or all of the properties defined on this Record. These properties will be lazily created whenever a property is attempted to be accessed with the values returned from this method.
quip.apps.Record.prototype
get
Function(prop: string) => any
Returns the stored property value for this key. If a value has not yet been set but this property has a value in getDefaultProperties()
, this will set the default value from getDefaultProperties()
and return it.
has
Function(prop: string) => boolean
Returns true if this Record has a value stored for this property.
This will return true only if this has been set explicitly (not defaulted) - hence, has(prop)
can return false
and get(prop)
may still return a value, if getDefaultProperties
has a default for the given prop.
getData
Function() => { [prop: keyof PropertySchema]: any }
Returns a dictionary of all the property values stored in the Record.
It is recommended that you override this method when using typescript, as it will not provide types for any of the data it returns.
set
Function(prop: string, value?: any) => void
This sets the value for a property on the given Record. We use the property schema to determine whether we should create a Record or RecordList, and if we do, what type of Record to create.
When setting a property that's of type Record or RecordList, if the property already has a stored value, this will throw an error. Developers need to clear the property before resetting it to a new value.
clear
Function(prop: string, skipDelete: boolean = false) => quip.apps.Record | quip.apps.RecordList | undefined
Clears a property on the Record. If the property is a Record or a RecordList, then the Record/RecordList will be deleted, unless skipDelete is true. If skipDelete is true, then we will not call delete on the Record/RecordList and will return a reference to it. This is intended to be used by developers to move a Record property from one object to another.
clearData
Function() => void
Clears all properties for the given Record.