| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168 |
- 'use strict';
- exports.__esModule = true;
- exports.RecordTranslator = undefined;
- var _createClass = function () { function defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } } return function (Constructor, protoProps, staticProps) { if (protoProps) defineProperties(Constructor.prototype, protoProps); if (staticProps) defineProperties(Constructor, staticProps); return Constructor; }; }();
- exports.registerIdentity = registerIdentity;
- exports.getTranslator = getTranslator;
- var _core = require('./../core');
- var _core2 = _interopRequireDefault(_core);
- var _object = require('./../helpers/object');
- function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
- function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
- /**
- * @class RecordTranslator
- * @util
- */
- var RecordTranslator = function () {
- function RecordTranslator(hot) {
- _classCallCheck(this, RecordTranslator);
- this.hot = hot;
- }
- /**
- * Translate physical row index into visual.
- *
- * @param {Number} row Physical row index.
- * @returns {Number} Returns visual row index.
- */
- _createClass(RecordTranslator, [{
- key: 'toVisualRow',
- value: function toVisualRow(row) {
- return this.hot.runHooks('unmodifyRow', row);
- }
- /**
- * Translate physical column index into visual.
- *
- * @param {Number} column Physical column index.
- * @returns {Number} Returns visual column index.
- */
- }, {
- key: 'toVisualColumn',
- value: function toVisualColumn(column) {
- return this.hot.runHooks('unmodifyCol', column);
- }
- /**
- * Translate physical coordinates into visual. Can be passed as separate 2 arguments (row, column) or as an object in first
- * argument with `row` and `column` keys.
- *
- * @param {Number|Object} row Physical coordinates or row index.
- * @param {Number} [column] Physical column index.
- * @returns {Object|Array} Returns an object with visual records or an array if coordinates passed as separate arguments.
- */
- }, {
- key: 'toVisual',
- value: function toVisual(row, column) {
- var result = void 0;
- if ((0, _object.isObject)(row)) {
- result = {
- row: this.toVisualRow(row.row),
- column: this.toVisualColumn(row.column)
- };
- } else {
- result = [this.toVisualRow(row), this.toVisualColumn(column)];
- }
- return result;
- }
- /**
- * Translate visual row index into physical.
- *
- * @param {Number} row Visual row index.
- * @returns {Number} Returns physical row index.
- */
- }, {
- key: 'toPhysicalRow',
- value: function toPhysicalRow(row) {
- return this.hot.runHooks('modifyRow', row);
- }
- /**
- * Translate visual column index into physical.
- *
- * @param {Number} column Visual column index.
- * @returns {Number} Returns physical column index.
- */
- }, {
- key: 'toPhysicalColumn',
- value: function toPhysicalColumn(column) {
- return this.hot.runHooks('modifyCol', column);
- }
- /**
- * Translate visual coordinates into physical. Can be passed as separate 2 arguments (row, column) or as an object in first
- * argument with `row` and `column` keys.
- *
- * @param {Number|Object} row Visual coordinates or row index.
- * @param {Number} [column] Visual column index.
- * @returns {Object|Array} Returns an object with physical records or an array if coordinates passed as separate arguments.
- */
- }, {
- key: 'toPhysical',
- value: function toPhysical(row, column) {
- var result = void 0;
- if ((0, _object.isObject)(row)) {
- result = {
- row: this.toPhysicalRow(row.row),
- column: this.toPhysicalColumn(row.column)
- };
- } else {
- result = [this.toPhysicalRow(row), this.toPhysicalColumn(column)];
- }
- return result;
- }
- }]);
- return RecordTranslator;
- }();
- exports.RecordTranslator = RecordTranslator;
- var identities = new WeakMap();
- var translatorSingletons = new WeakMap();
- function registerIdentity(identity, hot) {
- identities.set(identity, hot);
- }
- function getTranslator(identity) {
- var singleton = void 0;
- if (!(identity instanceof _core2.default)) {
- if (!identities.has(identity)) {
- throw Error('Record translator was not registered for this object identity');
- }
- identity = identities.get(identity);
- }
- if (translatorSingletons.has(identity)) {
- singleton = translatorSingletons.get(identity);
- } else {
- singleton = new RecordTranslator(identity);
- translatorSingletons.set(identity, singleton);
- }
- return singleton;
- }
|