|
|
@ -25,6 +25,9 @@ import '../app' |
|
|
|
* |
|
|
|
* |
|
|
|
* the data-async-load is the attribute responsible for binding the store. |
|
|
|
* the data-async-load is the attribute responsible for binding the store. |
|
|
|
* |
|
|
|
* |
|
|
|
|
|
|
|
* data-no-first-loading attribute can also be used along with data-async-load |
|
|
|
|
|
|
|
* to prevent loading items for the first time |
|
|
|
|
|
|
|
* |
|
|
|
* If the page has a redux associated with, you need to connect the reducers instead of creating |
|
|
|
* If the page has a redux associated with, you need to connect the reducers instead of creating |
|
|
|
* the store using the `createStore`. For instance: |
|
|
|
* the store using the `createStore`. For instance: |
|
|
|
* |
|
|
|
* |
|
|
@ -39,6 +42,8 @@ import '../app' |
|
|
|
* |
|
|
|
* |
|
|
|
*/ |
|
|
|
*/ |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
var enableFirstLoading = true |
|
|
|
|
|
|
|
|
|
|
|
export const asyncInitialState = { |
|
|
|
export const asyncInitialState = { |
|
|
|
/* it will consider any query param in the current URI as paging */ |
|
|
|
/* it will consider any query param in the current URI as paging */ |
|
|
|
beyondPageOne: (URI(window.location).query() !== ''), |
|
|
|
beyondPageOne: (URI(window.location).query() !== ''), |
|
|
@ -310,7 +315,10 @@ function firstPageLoad (store) { |
|
|
|
function loadItemsPrev () { |
|
|
|
function loadItemsPrev () { |
|
|
|
loadPage(store, store.getState().prevPagePath) |
|
|
|
loadPage(store, store.getState().prevPagePath) |
|
|
|
} |
|
|
|
} |
|
|
|
loadItemsNext() |
|
|
|
|
|
|
|
|
|
|
|
if (enableFirstLoading) { |
|
|
|
|
|
|
|
loadItemsNext() |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
$element.on('click', '[data-error-message]', (event) => { |
|
|
|
$element.on('click', '[data-error-message]', (event) => { |
|
|
|
event.preventDefault() |
|
|
|
event.preventDefault() |
|
|
@ -334,7 +342,12 @@ function firstPageLoad (store) { |
|
|
|
|
|
|
|
|
|
|
|
const $element = $('[data-async-load]') |
|
|
|
const $element = $('[data-async-load]') |
|
|
|
if ($element.length) { |
|
|
|
if ($element.length) { |
|
|
|
const store = createStore(asyncReducer) |
|
|
|
if (Object.prototype.hasOwnProperty.call($element.data(), 'noFirstLoading')) { |
|
|
|
connectElements({ store, elements }) |
|
|
|
enableFirstLoading = false |
|
|
|
firstPageLoad(store) |
|
|
|
} |
|
|
|
|
|
|
|
if (enableFirstLoading) { |
|
|
|
|
|
|
|
const store = createStore(asyncReducer) |
|
|
|
|
|
|
|
connectElements({ store, elements }) |
|
|
|
|
|
|
|
firstPageLoad(store) |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|