This Polymer behavior sets up everything you need to connect your element to Simpla's API. It handles setting and getting data, keeping in sync with state, and reacting to changes in content.
Install simpla-element-behavior with Bower (Yarn support coming soon)
$ bower install simpla-element-behavior --save
Import into your element
<link rel="import" href="/bower_components/simpla-element-behavior/simpla-element-behavior.html">
And include the behavior by adding SimplaBehaviors.Element(config)
in your behaviors array with the configuration options for your element (see full options below)
const SIMPLA_CONFIG = {
type: 'Text',
dataProperties: [ 'value' ]
};
Polymer({
is: 'my-element',
...
behaviors: [ SimplaBehaviors.Element(SIMPLA_CONFIG) ]
});
Property | Type | Description |
---|---|---|
type |
String |
Type of content created by this element (read more about Simpla's content model) |
dataProperties |
Array |
The properties you wish to sync to Simpla's API |
getCallback |
String |
Override the default method used to set properties on your element from Simpla, specified as the name of a method available on your element |
setCallback |
String |
Override the default method used to set data to Simpla's buffer, specified as the name of a method available on your element |
The setCallback
method expects you to return the values you wish to set to Simpla every time your dataProperties
change. If you return null
or undefined
the buffer is not updated.
This behavior adds the following properties to your element. Any property can be overriden by adding your own property definition of the same name in the main Polymer
constructor
Property | Type | Description |
---|---|---|
path |
String |
Content path where the element will store its data on Simpla's API, set by the user |
editable |
Boolean |
Whether the element should be editable, synced to Simpla's 'editable' state |
readonly |
Boolean |
Whether an element should be able to go editable |
loaded |
Boolean |
Whether a new path's data has been set on the element |
If you find any issues with simpla-element-behavior please report them! If you'd like to see a new feature in supported file an issue or let us know in Simpla's public Slack group. We also happily accept PRs.
MIT © Simpla