Bulk Updating
In addition to allowing for inline updating, violet-paginator
also exposes functions that can update every item within the list. This might be handy when implementing something like an inbox where you want to mark all messages as read
or important
. As with single item updating, bulk updating has both an immediate and an asynchronous version.
Async update
updateItemsAsync(itemIds, data, update)
Similar to updateAsync, but accepts a list of ids instead of a single id.
- Call
updateItems
to merge the properties from thedata
argument into each specified item. - Call
updatingItems
to indicate that all specified items are waiting for an update from the server. - Call the
update
promise, provided as the last argument toupdateItemsAsync
. - If the
update
promise fails, useresetResults
to revert the result list to its previous state. Then dispatchmarkItemsErrored
to indicate that the items failed to update.
Example:
import api from 'ROOT/api'
import { composables } from 'violet-paginator'
import * as actionTypes from './actionTypes'
const pageActions = composables({ listId: 'recipes' })
export function markAllRead(messageIds) {
const data = {
read: true
}
return pageActions.updateItemsAsync(
messageIds,
data,
api.messages.markAllRead(messageIds, data)
)
}
Instant Update
updateItems(itemIds, data)
Use the updateItems
action to instantly apply the provided data
to the items specified by the itemIds
. Example:
import { composables } from 'violet-paginator'
const pageActions = composables({ listId: 'recipes' })
export function toggleRead(recipeIds) {
return pageActions.updateAll(
recipeIds,
{ active: !recipe.get('active') }
)
}