Skip to content

Commit

Permalink
Changes after code review + additional TODO task in code. #3025
Browse files Browse the repository at this point in the history
  • Loading branch information
mrpiotr-dev committed Jun 12, 2017
1 parent 6e65b1d commit b500e5f
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 29 deletions.
42 changes: 23 additions & 19 deletions src/core.js
Expand Up @@ -2057,9 +2057,10 @@ export default function Core(rootElement, userSettings) {
* @memberof Core#
* @function getDataAtProp
* @since 0.9-beta2
* @param {String|Number} prop Property name / visual column index.
* @param {String|Number} prop Property name / physical column index.
* @returns {Array} Array of cell values.
*/
// TODO: Getting data from `datamap` should work on visual indexes.
this.getDataAtProp = function(prop) {
var out = [],
range;
Expand Down Expand Up @@ -2128,9 +2129,10 @@ export default function Core(rootElement, userSettings) {
* @memberof Core#
* @function getSourceDataAtCol
* @since 0.11.0-beta3
* @param {Number} column Physical column index.
* @param {Number} column Visual column index.
* @returns {Array} Array of the column's cell values.
*/
// TODO: Getting data from `sourceData` should work always on physical indexes.
this.getSourceDataAtCol = function(column) {
return dataSource.getAtColumn(column);
};
Expand All @@ -2154,10 +2156,11 @@ export default function Core(rootElement, userSettings) {
* @memberof Core#
* @function getSourceDataAtCell
* @param {Number} row Physical row index.
* @param {Number} column Physical column index.
* @param {Number} column Visual column index.
* @returns {*} Cell data.
* @since 0.20.0
*/
// TODO: Getting data from `sourceData` should work always on physical indexes.
this.getSourceDataAtCell = function(row, column) {
return dataSource.getAtCell(row, column);
};
Expand Down Expand Up @@ -2239,12 +2242,13 @@ export default function Core(rootElement, userSettings) {
*
* @memberof Core#
* @function removeCellMeta
* @param {Number} row Physical row index.
* @param {Number} col Physical column index.
* @param {Number} row Visual/physical row index.
* @param {Number} col Visual/physical column index.
* @param {String} key Property name.
*/
this.removeCellMeta = function(row, col, key) {
var cellMeta = instance.getCellMeta(row, col);
// TODO: First we use indexes as visual, after that, the same indexes are used as physical. This MUST be improved.
const cellMeta = instance.getCellMeta(row, col);
if (cellMeta[key] != undefined) {
delete priv.cellSettings[row][col][key];
}
Expand All @@ -2268,8 +2272,8 @@ export default function Core(rootElement, userSettings) {
* @memberof Core#
* @function setCellMetaObject
* @since 0.11
* @param {Number} row Physical row index.
* @param {Number} col Physical column index.
* @param {Number} row Visual row index.
* @param {Number} col Visual column index.
* @param {Object} prop Meta object.
*/
this.setCellMetaObject = function(row, col, prop) {
Expand All @@ -2289,8 +2293,8 @@ export default function Core(rootElement, userSettings) {
* @memberof Core#
* @function setCellMeta
* @since 0.11
* @param {Number} row Physical row index.
* @param {Number} col Physical column index.
* @param {Number} row Visual row index.
* @param {Number} col Visual column index.
* @param {String} key Property name.
* @param {String} val Property value.
* @fires Hooks#afterSetCellMeta
Expand Down Expand Up @@ -2408,8 +2412,8 @@ export default function Core(rootElement, userSettings) {
* @memberof Core#
* @function getCellRenderer
* @since 0.11
* @param {Number|Object} row Physical row index or cell meta object.
* @param {Number} [col] Physical column index.
* @param {Number|Object} row Visual row index or cell meta object.
* @param {Number} [col] Visual column index.
* @returns {Function} The renderer function.
*/
this.getCellRenderer = function(row, col) {
Expand All @@ -2421,8 +2425,8 @@ export default function Core(rootElement, userSettings) {
*
* @memberof Core#
* @function getCellEditor
* @param {Number} row Physical row index.
* @param {Number} col Physical column index.
* @param {Number} row Visual row index.
* @param {Number} col Visual column index.
* @returns {Object} The Editor object.
*/
this.getCellEditor = cellMethodLookupFactory('editor');
Expand All @@ -2434,8 +2438,8 @@ export default function Core(rootElement, userSettings) {
*
* @memberof Core#
* @function getCellValidator
* @param {Number} row Physical row index.
* @param {Number} col Physical column index.
* @param {Number} row Visual row index.
* @param {Number} col Visual column index.
* @returns {Function|RegExp|undefined} The validator function.
*/
this.getCellValidator = function(row, col) {
Expand Down Expand Up @@ -2493,7 +2497,7 @@ export default function Core(rootElement, userSettings) {
*
* @memberof Core#
* @function getRowHeader
* @param {Number} [row] Physical row index.
* @param {Number} [row] Visual row index.
* @fires Hooks#modifyRowHeader
* @returns {Array|String} Array of header values / single header value.
*/
Expand Down Expand Up @@ -2684,7 +2688,7 @@ export default function Core(rootElement, userSettings) {
* @private
* @memberof Core#
* @function _getRowHeightFromSettings
* @param {Number} row Physical row index.
* @param {Number} row Visual row index.
* @returns {Number}
*/
this._getRowHeightFromSettings = function(row) {
Expand Down Expand Up @@ -2722,7 +2726,7 @@ export default function Core(rootElement, userSettings) {
* @memberof Core#
* @function getRowHeight
* @since 0.11
* @param {Number} row Physical row index.
* @param {Number} row Visual row index.
* @returns {Number} The given row's height.
* @fires Hooks#modifyRowHeight
*/
Expand Down
16 changes: 8 additions & 8 deletions src/dataMap.js
Expand Up @@ -244,7 +244,7 @@ DataMap.prototype.createRow = function(index, amount, source) {
/**
* Creates col at the right of the data array.
*
* @param {Number} [index] Physical index of the column before which the new column will be inserted
* @param {Number} [index] Visual index of the column before which the new column will be inserted
* @param {Number} [amount] An amount of columns to add.
* @param {String} [source] Source of method call.
* @fires Hooks#afterCreateCol
Expand Down Expand Up @@ -312,7 +312,7 @@ DataMap.prototype.createCol = function(index, amount, source) {
/**
* Removes row from the data array.
*
* @param {Number} [index] Physical index of the row to be removed. If not provided, the last row will be removed
* @param {Number} [index] Visual index of the row to be removed. If not provided, the last row will be removed
* @param {Number} [amount] Amount of the rows to be removed. If not provided, one row will be removed
* @param {String} [source] Source of method call.
* @fires Hooks#beforeRemoveRow
Expand All @@ -330,7 +330,7 @@ DataMap.prototype.removeRow = function(index, amount, source) {

index = (this.instance.countSourceRows() + index) % this.instance.countSourceRows();

let logicRows = this.physicalRowsToVisual(index, amount);
let logicRows = this.visualRowsToPhysical(index, amount);
let actionWasNotCancelled = this.instance.runHooks('beforeRemoveRow', index, amount, logicRows, source);

if (actionWasNotCancelled === false) {
Expand All @@ -355,7 +355,7 @@ DataMap.prototype.removeRow = function(index, amount, source) {
/**
* Removes column from the data array.
*
* @param {Number} [index] Physical index of the column to be removed. If not provided, the last column will be removed
* @param {Number} [index] Visual index of the column to be removed. If not provided, the last column will be removed
* @param {Number} [amount] Amount of the columns to be removed. If not provided, one column will be removed
* @param {String} [source] Source of method call.
* @fires Hooks#beforeRemoveCol
Expand All @@ -374,7 +374,7 @@ DataMap.prototype.removeCol = function(index, amount, source) {

index = (this.instance.countCols() + index) % this.instance.countCols();

let logicColumns = this.physicalColumnsToVisual(index, amount);
let logicColumns = this.visualColumnsToPhysical(index, amount);
let descendingLogicColumns = logicColumns.slice(0).sort((a, b) => b - a);
let actionWasNotCancelled = this.instance.runHooks('beforeRemoveCol', index, amount, logicColumns, source);

Expand Down Expand Up @@ -649,7 +649,7 @@ DataMap.prototype.set = function(row, prop, value, source) {
* @fires Hooks#modifyRow
* @returns {Number}
*/
DataMap.prototype.physicalRowsToVisual = function(index, amount) {
DataMap.prototype.visualRowsToPhysical = function(index, amount) {
var totalRows = this.instance.countSourceRows();
var physicRow = (totalRows + index) % totalRows;
var logicRows = [];
Expand All @@ -669,11 +669,11 @@ DataMap.prototype.physicalRowsToVisual = function(index, amount) {

/**
*
* @param index Physical column index.
* @param index Visual column index.
* @param amount
* @returns {Array}
*/
DataMap.prototype.physicalColumnsToVisual = function(index, amount) {
DataMap.prototype.visualColumnsToPhysical = function(index, amount) {
let totalCols = this.instance.countCols();
let physicalCol = (totalCols + index) % totalCols;
let visualCols = [];
Expand Down
4 changes: 2 additions & 2 deletions src/pluginHooks.js
Expand Up @@ -869,9 +869,9 @@ const REGISTERED_HOOKS = [
/**
* Fired when a data was retrieved or modified.
*
* @event Hooks#modifyRowSourceData
* @event Hooks#modifyRowData
* @since 0.28.0
* @param {Number} row Visual row index.
* @param {Number} row Physical row index.
*/
'modifyRowData',

Expand Down

0 comments on commit b500e5f

Please sign in to comment.