Skip to content
This repository has been archived by the owner on Mar 30, 2019. It is now read-only.

Collections

ScottDowne edited this page Jun 12, 2014 · 15 revisions

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.

The Collection Object

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.

Collection Functions

collections.addSchema(name)

collections.removeSchema(name)

collections.getSchema(name)

collections.getSchemas()

collections.getField(schemaname, fieldname)

collections.getFields(name)

Collection Events

Listen for changes in schema or data. You can add events using collections.addEventListener(event, function(detail) {})

schemachange

detail.added detail.removed

Schemas

The Schema Object

var schema = collection.getSchemas()[0];

schema is a thing you can call schema related functions from. You can access this and use it from inside your component.

Schema Functions

schema.addField(name)

schema.removeField(name)

schema.getField(name)

schema.getFields()

schema.name

schema.addItem(item)

schema.removeItem(index)

schema.updateItem(index, item)

schema.saveData()

Schema Events

Listen for changes in schema or data. You can add events using schema.addEventListener(event, function(detail) {})

itemchange

detail.added detail.removed detail.index

fieldchange

detail.added detail.removed

propertychange

detail.changed

Fields

The Field Object

var field = schema.getFields()[0];

field is a thing you can call field related functions from. You can access this and use it from inside your component.

Field Functions

field.kind

field.name

field.getSchemaName()

Field Events

propertychange

detail.changed

What Simon Hopes It'll Look Like:

var collections = document.querySelector("ceci-collection");

collections.addCollection('things');

collecitons.things.addField('name', collections.kinds.Text);
collecitons.things.addField('value', collections.kinds.Number);

collections.things.fields 
=> { // dunno if this is right
    name: collections.kinds.Text
    value: collections.kinds.Number
  }
]

collections.things // returns localStorage['ceci-collection-things']
=> [
]

collections.things.push({
  name: "Fart Machine",
  value: Infinity
});

collections.things
=> [
  {name: "Fart Machine", value: Infinity}
]