Mixin: module:delite/Store

module:delite/Store

Mixin for store management that creates render items from store items after querying the store. The receiving class must extend decor/Evented or delite/Widget.

Classes extending this mixin automatically create render items that are consumable from store items after querying the store. This happens each time the store, query or queryOptions properties are set. If that store is Trackable it will be observed and render items will be automatically updated, added or deleted based on store notifications.

Source:
Show inherited

Members

deliver

Synchronously deliver change records to all listeners registered via observe().

Source:

discardChanges

Discard change records for all listeners registered via observe().

Source:

query :Object

A query filter to apply to the store.

Type:
  • Object
Default Value:
  • {}
Source:

renderItems :Array.<Object>

The render items corresponding to the store items for this widget. This is filled from the store and is not supposed to be modified directly. Initially null.

Type:
  • Array.<Object>
Default Value:
  • null
Source:

source :dstore/Store|decor/ObservableArray|Array

The source that contains the items to display.

Type:
  • dstore/Store | decor/ObservableArray | Array
Default Value:
  • null
Source:

Methods

<protected> computeProperties(props, isAfterCreation)

If the store parameters are invalidated, queries the store, creates the render items and calls initItems() when ready. If an error occurs a 'query-error' event will be fired.

Parameters:
Name Type Description
props
isAfterCreation
Source:

<protected> fetch(collection)

Called to perform the fetch operation on the collection.

Parameters:
Name Type Description
collection dstore/Collection

Items to be displayed.

Source:

<protected> getIdentity(item) → {Object}

Return the identity of an item.

Parameters:
Name Type Description
item Object

The item

Source:
Returns:
Type
Object

<protected> initItems(renderItems) → {Array.<Object>}

This method is called once the query has been executed to initialize the renderItems array with the list of initial render items.

This method sets the renderItems property to the render items array passed as parameter. Once done, it fires a 'query-success' event.

Parameters:
Name Type Description
renderItems Array.<Object>

The array of initial render items to be set in the renderItems property.

Source:
Fires:
Returns:

the renderItems array.

Type
Array.<Object>

<protected> itemAdded(index, renderItem, renderItems)

This method is called when an item is added in an observable store. The default implementation actually adds the renderItem to the renderItems array. This can be redefined but must not be called directly.

Parameters:
Name Type Description
index number

The index where to add the render item.

renderItem Object

The render item to be added.

renderItems Array.<Object>

The array of render items to add the render item to.

Source:

<protected> itemMoved(previousIndex, newIndex, renderItem, renderItems)

This method is called when an item is moved in an observable store. The default implementation actually moves the renderItem in the renderItems array. This can be redefined but must not be called directly.

Parameters:
Name Type Description
previousIndex number

The previous index of the render item.

newIndex number

The new index of the render item.

renderItem Object

The render item to be moved.

renderItems Array.<Object>

The array of render items to render item to be moved is part of.

Source:

<protected> itemRemoved(index, renderItems)

This method is called when an item is removed from an observable store. The default implementation actually removes a renderItem from the renderItems array. This can be redefined but must not be called directly.

Parameters:
Name Type Description
index number

The index of the render item to remove.

renderItems Array.<Object>

The array of render items to remove the render item from.

Source:

<protected> itemToRenderItem(item) → {Object}

Returns the widget internal item for a given store item. By default it returns the store item itself.

Parameters:
Name Type Description
item Object

The store item.

Source:
Returns:
Type
Object

<protected> itemUpdated(index, renderItem, renderItems)

This method is called when an item is updated in an observable store. The default implementation actually updates the renderItem in the renderItems array. This can be redefined but must not be called directly.

Parameters:
Name Type Description
index number

The index of the render item to update.

renderItem Object

The render item data the render item must be updated with.

renderItems Array.<Object>

The array of render items to render item to be updated is part of.

Source:

<protected> processCollection(collection)

Called to process the items returned after querying the store.

Parameters:
Name Type Description
collection dstore/Collection

Items to be displayed.

Source:

processQueryResult()

A function that processes the collection or the array returned by the source query and returns a new collection or a new array (to sort it, etc...). This processing is applied before potentially tracking the source for modifications (if Trackable or Observable). Be careful you can not use the same function for both arrays and collections. Changing this function on the instance will not automatically refresh the class.

Default Value:
  • identity function
Source:

<protected> queryStoreAndInitItems(processQueryResult) → {Promise}

Queries the store, creates the render items and calls initItems() when ready. If an error occurs a 'query-error' event will be fired.

This method is not supposed to be called by application developer. It will be called automatically when modifying the store related properties or by the subclass if needed.

Parameters:
Name Type Description
processQueryResult

A function that processes the collection returned by the store query and returns a new collection (to sort it, etc...)., applied before tracking.

Source:
Returns:

If store to be processed is not null a promise that will be resolved when the loading process will be finished.

Type
Promise

renderItemToItem(renderItem) → {Object}

Creates a store item based from the widget internal item.

Parameters:
Name Type Description
renderItem Object

The render item.

Source:
Returns:
Type
Object

Events

query-success

Dispatched once the query has been executed and the renderItems array has been initialized with the list of initial render items.

Properties:
Name Type Description
renderItems Array.<Object>

The array of initial render items.

cancelable boolean

Indicates whether the event is cancelable or not.

bubbles boolean

Indicates whether the given event bubbles up through the DOM or not.

Source:
Example
widget.on("query-success", function (evt) {
     console.log("query done, initial renderItems: " + evt.renderItems);
});