У меня есть фабрика контроллера пейджинга, которая возвращает объект контроллера пейджинга с кучей методов (для представления, с которым нужно взаимодействовать, особенно, когда конечный пользователь выполняет действие, такое как переход на другую страницу или ввод текста поиска),Он определяется примерно так:
/**
* Returns a paging controller object with data
* @param {Object[]} data
* @param {string} prop the property containing that data. If it's a function, it should be no-args.
* @param {filterFunc} filterer a callback that filters the data
*/
function pagingControllerFor(data, prop, filterer) {
let _currentPage = 0
let _filterFunc = filterer
let _stateChange = false
let _data;
const _ITEMS_PER_PAGE = 50
let _selectAllChecked = [];
/**
* Getter for all the data. Useful for debugging.
*/
function getAllData() {
if (prop) {
if (typeof data[prop] === 'function') {
return data[prop]()
}
return data[prop]
}
return data
}
/**
* Always returns fresh data for the controller
*/
function getData() {
let data = getAllData()
if (_filterFunc) {
if ((_stateChange) || (!_data)) {
_data = data.filter(_filterFunc)
_selectAllChecked = Array(Math.ceil(_data.length / _ITEMS_PER_PAGE)).fill(false)
_stateChange = false
}
return _data
}
return data
}
return {
/* a whole bunch of methods irrelevant to my use case on here */
getCurrentPageData : () => getData().slice(_currentPage * _ITEMS_PER_PAGE, (_currentPage + 1) * _ITEMS_PER_PAGE),
// get/set current "Select All" checkbox state
isCurrentSelectAllChecked : () => _selectAllChecked[_currentPage],
setCurrentSelectAllChecked : (checked) => _selectAllChecked[_currentPage] = checked
}
}
Я пишу привязку событий для флажков «Выбрать / отменить выбор всех» в разбивке на страницы.На момент написания этой статьи он был определен следующим образом:
/**
* Binds clicks on the current "Select/Deselect All" checkbox to the controller
* @param {string} modalType
* @param {{ getCurrentPageData : () => Array<{IsSelectedOnModal : boolean}>, setCurrentSelectAllChecked : () => boolean }} controller
* @param {Function} callback
*/
function bindToggleSelectAllEvent(modalType, controller, callback) {
callback = callback || bindToggleSelectAllEvent
const modalSelector = `#${modalType}-selector-modal`
$(`#toggle-all-${(modalType === ITEM) ? 'items' : 'categories'}-selected`)
.off('change')
.on('change', function() {
// get the state of this
let isChecked = $(this).prop('checked')
// change the selection state of all current items/categories in the controller to that state
controller.getCurrentPageData().forEach((data) => {
data.IsSelectedOnModal = isChecked
})
// tell the controller the new state of this "Select All" checkbox
controller.setCurrentSelectAllChecked(isChecked)
// Re-render modal?!
// TODO: implement this
})
}
VSCode знает, что я делаю, так как он обнаруживает соответствующие методы controller
, которые я указал.
Однако JSDoc по какой-то причине этого не делает:
ERROR: Unable to parse a tag's type expression for source file [my-project-path]\static\js\menu\edit\index.js in line 433 with tag title "param" and text "{{ getCurrentPageData : () => Array<{IsSelectedOnModal : boolean}>, setCurrentSelectAllChecked : () => boolean }} controller": Invalid type expression "{ getCurrentPageData : () => Array<{IsSelectedOnModal : boolean}>, setCurrentSelectAllChecked : () => boolean }": Expected "," or "}" but "=" found.
ERROR: Unable to parse a tag's type expression for source file [my-project-path]\static\js\menu\edit\index.js in line 439 with tag title "param" and text "{{ getCurrentPageData : () => Array<{IsSelectedOnModal : boolean}>, setCurrentSelectAllChecked : () => boolean }} controller": Invalid type expression "{ getCurrentPageData : () => Array<{IsSelectedOnModal : boolean}>, setCurrentSelectAllChecked : () => boolean }": Expected "," or "}" but "=" found.
Что мне делать с этим?