Mixin: module:delite/StoreMap

module:delite/StoreMap

Mixin providing store binding management for widgets that extend delite/Store. Classes extending this mixin can easily define how store items properties are mapped in the render items properties consumable by the widget. The mapping can either occur by property (property A in store item corresponds to property B in render item) or by function (a function is specified that mapped the store item into the value of a property of the render item)..

For each mapped property "foo" from the render item one can provide:

  • fooAttr property in which case the mapping is looking into the store item property specified by fooAttr
  • fooFunc property function in which case the mapping is delegating the mapping operation to the fooFunc function.
  • fooFunc is of the following signature (value must be passed only for set operations: fooFunc(item, store, value)
  • if none of this is provided the mapping is looking into store item "foo" property

Mapping properties are meant to be added to the widget class using the mixin. One can directly add the mapping properties to an instance but in this case there are two limitations:

  • The property must be added before the widget is started
  • If the property is added in the markup only fully lower case properties are supported (e.g. foobar not fooBar)
Source:

Extends

Show inherited

Members

allowRemap :boolean

Whether the created render items will be updated when call the remap() function on the component allowing the consuming component to re-perform the mapping on demand. This property must not be changed after the initialization cycle.

Type:
  • boolean
Default Value:
  • false
Source:

copyAllItemProps :boolean

If true, in addition to the mapped properties copy all the other properties of the store item into the render item with direct mapping. This property must not be changed after the initialization cycle.

Type:
  • boolean
Default Value:
  • false
Source:

query :Object

A query filter to apply to the store.

Type:
  • Object
Inherited From:
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>
Inherited From:
Default Value:
  • null
Source:

store :dstore/Store

The store that contains the items to display.

Type:
  • dstore/Store
Inherited From:
Default Value:
  • null
Source:

Methods

<protected> computeProperties(props)

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
Inherited From:
Source:

<protected> fetch(collection)

Called to perform the fetch operation on the collection.

Parameters:
Name Type Description
collection dstore/Collection

Items to be displayed.

Inherited From:
Source:

<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.

Inherited From:
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.

Inherited From:
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.

Inherited From:
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.

Inherited From:
Source:

<protected> itemToRenderItem(item) → {Object}

Returns the widget internal item for a given store item based on the various mapped properties.

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.

Inherited From:
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.

Inherited From:
Source:

processQueryResult()

A function that processes the collection returned by the store query and returns a new collection (to sort it, etc...). This processing is applied before potentially tracking the store for modifications (if Trackable). Changing this function on the instance will not automatically refresh the class.

Inherited From:
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.

Inherited From:
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

remap()

If allowRemap is true, the method allows to perform again the mapping between the data item and the render items. This might be useful is mapping by function is used and the execution context of the mapping function as changed so that the results would need to be updated. It should not be called if allowRemap is false.

Source:

renderItemToItem(renderItem) → {Promise}

Creates a store item based from the widget internal item based on the various mapped properties. Works asynchronously.

Parameters:
Name Type Description
renderItem Object

The render item.

Source:
Returns:
Type
Promise

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.

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