DruxtViewsStore
DruxtViewsStore
Vuex module, registered under the druxt/views namespace.
The druxt/views Vuex module.
Provides a Vuex state object, mutations and actions for interacting with JSON:API Views.
See: The DruxtStore
- druxt/views
- action
- getResults(context, payload) ⇒
object|boolean
- getResults(context, payload) ⇒
- state :
object - mutation
- action
getResults(context, payload) ⇒ object | boolean
Get View results.
- Executes query against Drupal JSON:API.
- Caches result in the Vuex store.
- Returns cached result from Vuex store when available.
Vuex Action => Mutates state propertyresults
Kind: action method of druxt/views
Returns: object | boolean - The JSON:API Views results resource, or false where the request failed with nothing cached.
| Param | Type | Description |
|---|---|---|
| context | object | The Vuex action context. |
| context.commit | function | Commits mutations to the store. |
| context.state | object | The Vuex module state. |
| payload | getResultsContext | The action parameters. |
Example
const { data, meta, links } = await this.$store.dispatch('druxt/views/getResults', {
viewId,
displayId,
query,
bypassCache: false
})
state : object
Vuex State object.
Read only: true
Properties
| Name | Type | Description |
|---|---|---|
| results | object | JSON:API Views results store. |
addResults
Adds JSON:API Views results to the Vuex state object.
Kind: mutation method of druxt/views
| Param | Type | Description |
|---|---|---|
| state | object | The Vuex state object. |
| payload | addResultsPayload | The mutation payload. |
Example
this.$store.commit('druxt/views/addResults', { results, viewId, displayId, prefix, hash })
flushResults
Removes JSON:API Views results from the Vuex state object.
Kind: mutation method of druxt/views
| Param | Type | Description |
|---|---|---|
| state | object | The Vuex state object. |
| payload | flushResultsPayload | The mutation payload. |
Example
// Flush all results.
this.$store.commit('druxt/views/flushResults', {})
// Flush target results.
this.$store.commit('druxt/views/flushResults', { viewId, displayId, prefix, hash })
addResultsPayload : object
Parameters for the addResults mutation.
Kind: global typedef
| Param | Type | Description |
|---|---|---|
| results | array | The Drupal JSON:API Views results. |
| viewId | string | The Drupal View ID. |
| displayId | string | The Drupal View Display ID. |
| [prefix] | string | (Optional) The JSON:API endpoint prefix or langcode. |
| hash | string | A unique hash based of the query string. |
Example
{
results: [{ ... }],
viewId: 'promoted_items',
displayId: 'block_1',
prefix: 'en',
hash: '_default'
}
flushResultsPayload : object
Parameters for the flushResults mutation.
Kind: global typedef
| Param | Type | Description |
|---|---|---|
| [viewId] | string | The Drupal View ID. |
| [displayId] | string | The Drupal View Display ID. |
| [prefix] | string | (Optional) The JSON:API endpoint prefix or langcode. |
| [hash] | string | A unique hash based of the query string. |
Example
{
viewId: 'promoted_items',
displayId: 'block_1',
prefix: 'en',
hash: '_default'
}
getResultsContext : object
Parameters for the getResults action.
Kind: global typedef
| Param | Type | Description |
|---|---|---|
| viewId | string | The Drupal View ID. |
| displayId | string | The Drupal View Display ID. |
| [query] | string | object | (Optional) JSON:API Views query string. |
| [prefix] | string | (Optional) The JSON:API endpoint prefix or langcode. |
| [bypassCache] | boolean | (Optional) Bypass the Vuex cached results. |
Example
{
viewId: 'promoted_items',
displayId: 'block_1',
query: new DrupalJsonApiParams(),
prefix: 'en',
bypassCache: true
}