Repository navigation
Collections
A shared data storage that components can use. Example: A component that creates and stores form data, can store it in the collections so another component can see or use the same data. It'll save it, and persist between app loads.
var collections = document.querySelector("ceci-collections");
collections is a thing you can call collections related functions from. You can access this and use it from inside your component.
collections.schema and collections.data are objects you can explore to see the existing data and scehma stored in the collections.
collections.schema looks like this:
{
"schemaname": {
"fieldname": {
"fieldproperty": value
}
}
}
An example schema set:
{
"contacts": {
"address": {
"type": "Address"
},
"name": {
"type": "Name"
},
"description": {
"type": "Text"
}
},
"pets": {
"owner": {
"type": "Name"
},
"name": {
"type": "Name"
}
}
}
collections.data looks like this:
{
"schemaname": [
{
"fieldname": value
},
{
"fieldname": value
}
]
}
An example data set:
{
"contacts": [
{
"address": "123 component st",
"name": "Component Button",
"description": "Mr. Button is a model citizen. "
},
{
"address": "123 schema st",
"name": "Schema Contact",
"description": "Mr. Contact is a model schema. "
}
]
}
To add a collection, call collections.addCollection to update a collection, call collections.updateCollection and to remove one call collections.removeCollection
collections.addCollection(collectionName);
This adds an empty collection under the key collectionName
collections.updateCollection(existingCollection, newCollection);
This updates existingCollection to now be newCollection
collections.removeCollection(collectionName);
This removes an existing collection added under the key collectionName
To add a schema field call collections.addField, to update a field call collections.updateField and to remove a schema field call collections.removeField
collections.addField(collection, name, data);
collection a string for the collection to store this field under.
name a string for the name of the new field.
data an optional object for any properties used for this field.
collections.updateField(collection, name, data);
collection a string for the collection to store this field under.
name a string for the name of the existing field.
data a new object for to replace the existing one with.
collections.removeField(collection, name);
collection a string for the collection that this field is under.
name a string for the name of the field to remove.
To push a data item in collections.data use collections.addItem, to update an item use collections.updateItem and to remove one, use collections.removeItem
collections.addItem(collection, data);
collection a string for the name to store this data item under.
data an object to store as the data set under collection
collections.updateItem(collection, index, data);
collection a string for the name to store this data item under.
index the index for the data to be replaced.
data the new data to replace the existing data with.
collections.removeItem(collection, index);
collection a string for the collection the data lives under.
index the index for the data to be removed.
A schema is saved when the app itself is saved.
collections.saveData();
Saves whatever is in collections.data Call this function inside your component, example, a submit button would call this function.
Component authoers can listen for changes in schema or data.
collections.addEventListener("collectionchange", function(e) {
e.detail.added // Name of new collection
e.detail.removed // Name of removed collection
});
collections.addEventListener("fieldchange", function(e) {
e.detail.collection // Collection that has the field being changed
e.detail.field // Name of the field being changed
e.detail.added // Added field data
e.detail.removed // Removed field data
});
collections.addEventListener("itemchange", function(e) {
e.detail.collection // Collection that has the field being changed
e.detail.added // Added item data
e.detail.removed // Removed item data
});