_StoreBasedItemWidgetMixin

A widget can use this mixin when it wants to manage sub widgets based on objects in a store.

  • This mixin can be used by putting objects in the store.
  • This mixin will create an instance of the widget defined (by the itemWidget property).
  • When an object is deleted from the store, the widget is automatically destroyed.
  • When an object is updated the updated object is set at the subwidget. This subwidget can watch this property to update the UI.
Example
// @formatter:off
define([
  "dojo/_base/declare",
  "dojo/store/Memory",
  "dojo/store/Observable",
  "dijit/_WidgetBase",
  "blueconic/api/widgets/mixins/_StoreBasedItemWidgetMixin",
  "./ItemWidget" // your custom widget which represents an item in the store
// @formatter:on
], function(declare, Memory, Observable, _WidgetBase, _StoreBasedItemWidgetMixin, ItemWidget) {
  return declare("your.package.widget", [_WidgetBase, _StoreBasedItemWidgetMixin], {
    postCreate: function() {
      var store = new Observable(new Memory());

      // the important properties of the mixin are set here
      this.itemWidget = ItemWidget;
      this.itemsNode = this.domNode;
      this.store = store;

      // call super
      this.inherited(arguments);

      // for each item added to the store, an instance of "ItemWidget" is created and
      // attached to the DOMNode specified in "itemsNode".
      // the value is passed to the instance in the "item" property
      store.add({
        id: "id property 1"
      });
    }
    // other methods
  });
});

Properties

itemsNode DOMNode

The DOMNode where the widgets will be attached to.

itemWidget WidgetClass

The widget class representing your store item.

store dojo/Store

Optional
A Observable store can be specified to work on. If not specified, an observable (Memory) store is created for you.

Functions

bindHandlers(widget)

Extension point to give the possibility to define handlers for the widget, after the widget has been created.

Name Type Description
widget Object

The widget which is created.

getWidget(id)

Retrieve the widget, based on the id of the object from the store.

Name Type Description
id String

Id of the object in the store.

updateStore(entries, preserveOrder)

Update the entries in the store by passing an array of items.

Name Type Description
entries Array.<Object>

The entries to update the store with. Existing items not in this list, are deleted.

preserveOrder boolean

whether to maintain the order of the entries