Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Migrate Core modules to TS #28135

Closed
wants to merge 59 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
59 commits
Select commit Hold shift + click to select a range
5524478
Core: Move js -> ts
ivanblinov2k17 Oct 2, 2024
cac96a4
Core: fix auto-fixable lint + create re-exports
ivanblinov2k17 Oct 3, 2024
d8aa70f
Core: fix imports
ivanblinov2k17 Oct 3, 2024
4c3da97
Core: fix imports for templates
ivanblinov2k17 Oct 4, 2024
dd3cf72
Core: fix/ignore eslint errors
ivanblinov2k17 Oct 4, 2024
215e9e3
Core: fix most of typescript issues
ivanblinov2k17 Oct 4, 2024
9bda437
Core: fix most of extraneous TS errors (mostly redundant ts-expect-er…
ivanblinov2k17 Oct 4, 2024
eeddf36
Core: fix/ignore remaining extraneous errors
ivanblinov2k17 Oct 4, 2024
0e0787a
Core: fix broken renovation import
ivanblinov2k17 Oct 4, 2024
ae5d76d
Core: fixed callOnce import
ivanblinov2k17 Oct 7, 2024
3a7bb50
Core: fix TS lint errors
ivanblinov2k17 Oct 7, 2024
b825114
Core: fix component_registrator_callbacks reexport
ivanblinov2k17 Oct 7, 2024
da87199
Core: fixed missed Data reexport + silence Mock TS error
ivanblinov2k17 Oct 7, 2024
4ac9e55
Core: fixed unwanted refactoring for renderer (using array methods on…
ivanblinov2k17 Oct 7, 2024
bb475cd
Core: add missing template reexport
ivanblinov2k17 Oct 7, 2024
1f03eb5
Core: fix artifacts of auto-replace
ivanblinov2k17 Oct 7, 2024
b7f0a10
Core: Fix data and utils modules
ivanblinov2k17 Oct 8, 2024
36683b9
Core: fix Error constructor
ivanblinov2k17 Oct 8, 2024
491aa09
Core: fix viewport IIFE after lint changes and add it to lint ignore
ivanblinov2k17 Oct 10, 2024
497c50d
Core: TEST - add lint ignore for all core, bring back changes, that s…
ivanblinov2k17 Oct 10, 2024
daa38f6
Core: TEST - bring back non-significant cahanges to see if they impac…
ivanblinov2k17 Oct 10, 2024
cff382f
Core: fix tests for editors and core
ivanblinov2k17 Oct 10, 2024
6cadf2f
Core: fix qunit part 2
ivanblinov2k17 Oct 11, 2024
ccd66d3
Core: common default export + bring back executeAsyncMock 10 line
ivanblinov2k17 Oct 11, 2024
5519d8b
Core: fix textbox hanging test (blur)
ivanblinov2k17 Oct 11, 2024
478ee75
Core: fix test Html editor - PopupModule mock window
ivanblinov2k17 Oct 11, 2024
4aaf069
Core: fix transitionExecutor + datebox knockout tests
ivanblinov2k17 Oct 14, 2024
95e1117
Core: fix animation/fx tests
ivanblinov2k17 Oct 14, 2024
00c5566
Core: fix animation/fx test part 2
ivanblinov2k17 Oct 14, 2024
92a144d
Core: fix imageCreator exporter test
ivanblinov2k17 Oct 15, 2024
6d33c22
Core: fix defaultOption tests
ivanblinov2k17 Oct 15, 2024
ade4267
Merge branch '24_2' into core_ts
ivanblinov2k17 Oct 15, 2024
b37627b
Core: fix azure provider TS error
ivanblinov2k17 Oct 15, 2024
164207c
Core: fix m_svg to contain default export
ivanblinov2k17 Oct 15, 2024
7fcf5e2
Core: fix popup test
ivanblinov2k17 Oct 15, 2024
2e45a4e
Core: fix regular popup tests
ivanblinov2k17 Oct 15, 2024
f569026
Core: Fix toolbar + loadIndicator
ivanblinov2k17 Oct 15, 2024
b5534bd
Core: Fix viz pieChart + rangeSelector
ivanblinov2k17 Oct 15, 2024
1dd59f6
Core: fix desktopTooltip test
ivanblinov2k17 Oct 15, 2024
e6de5e6
Core: fix ui-firefox
ivanblinov2k17 Oct 15, 2024
1c03fbb
Core: Replace all imports Action, devices -> m_action, m_devices
ivanblinov2k17 Oct 15, 2024
9295483
Core: domAdapter -> m_dom_adapter tests
ivanblinov2k17 Oct 15, 2024
49909d6
Core: fix m_action export
ivanblinov2k17 Oct 15, 2024
86f4714
Core: replace import support -> m_support
ivanblinov2k17 Oct 15, 2024
8ae7c9a
Core: dom -> m_dom;: common, type -> m_ only for helpers
ivanblinov2k17 Oct 15, 2024
83f38ad
Core: fix ui-firefox single test failures
ivanblinov2k17 Oct 15, 2024
c2ce666
Core: fix rowsView test
ivanblinov2k17 Oct 16, 2024
96e66d0
Core: fix pivotGrid async mocks
ivanblinov2k17 Oct 16, 2024
c353115
Core: fix pivotGrid dataSource.bundled
ivanblinov2k17 Oct 16, 2024
202a89d
Core: dataSource bundled add missing inflector import
ivanblinov2k17 Oct 16, 2024
8437164
Core: internal support -> m_support
ivanblinov2k17 Oct 16, 2024
6b4a9e5
Core: use ts device in events to try to fix mobile tests
ivanblinov2k17 Oct 16, 2024
969c203
Core: remove unexpected ts-error
ivanblinov2k17 Oct 16, 2024
2fb8e45
Core: replace dom->m_dom click event
ivanblinov2k17 Oct 17, 2024
e4fd6fb
Core: fix scrollable test (in mobileViewport)
ivanblinov2k17 Oct 17, 2024
28296da
Fix eslint rules and apply them to utils, templates, options and igno…
ivanblinov2k17 Oct 17, 2024
a061091
Core: modify eslint config, save core files
ivanblinov2k17 Oct 17, 2024
9630e2b
Core: fix metadata
ivanblinov2k17 Oct 18, 2024
7fe2c80
Core: fix TS lint
ivanblinov2k17 Oct 18, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
The table of contents is too big for display.
Diff view
Diff view
  •  
  •  
  •  
22 changes: 22 additions & 0 deletions packages/devextreme/js/__internal/.eslintrc.js
Original file line number Diff line number Diff line change
Expand Up @@ -199,6 +199,28 @@ module.exports = {
'@typescript-eslint/explicit-function-return-type': 'warn'
}
},
// Rules for migrated core files.
{
files: [
'**/core/**/m_*.ts',
],
parser: '@typescript-eslint/parser',
parserOptions: {
createDefaultProgram: true,
project: './tsconfig.json',
tsconfigRootDir: __dirname,
},
rules: {
'guard-for-in': 'off',
'no-restricted-syntax': 'off',
'func-style': 'off',
'wrap-iife': 'off',
'prefer-arrow-callback': 'off',
'@typescript-eslint/prefer-optional-chain': 'off',
'radix': 'off',
'object-shorthand': 'off'
},
},
],
settings: {
'import/resolver': {
Expand Down
174 changes: 174 additions & 0 deletions packages/devextreme/js/__internal/core/m_action.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,174 @@
/* eslint-disable guard-for-in */
/* eslint-disable @typescript-eslint/prefer-for-of */
/* eslint-disable no-restricted-syntax */
import $ from '@js/core/renderer';
import { each } from '@js/core/utils/iterator';
import { isFunction, isPlainObject } from '@js/core/utils/type';
import { getWindow } from '@js/core/utils/window';

class Action {
_action: any;

_context: any;

_beforeExecute: any;

_afterExecute: any;

_component: any;

_validatingTargetName: any;

_excludeValidators: any;

static executors: any;

constructor(action, config?) {
config = config || {};
this._action = action;
this._context = config.context || getWindow();
this._beforeExecute = config.beforeExecute;
this._afterExecute = config.afterExecute;
this._component = config.component;
this._validatingTargetName = config.validatingTargetName;
const excludeValidators = this._excludeValidators = {};

if (config.excludeValidators) {
for (let i = 0; i < config.excludeValidators.length; i++) {
excludeValidators[config.excludeValidators[i]] = true;
}
}
}

execute(...args) {
const e = {
action: this._action,
args: Array.prototype.slice.call(args),
context: this._context,
component: this._component,
validatingTargetName: this._validatingTargetName,
cancel: false,
handled: false,
};

const beforeExecute = this._beforeExecute;
const afterExecute = this._afterExecute;

const argsBag = e.args[0] || {};

if (!this._validateAction(e)) {
return;
}

beforeExecute?.call(this._context, e);

if (e.cancel) {
return;
}

const result = this._executeAction(e);

if (argsBag.cancel) {
return;
}

afterExecute?.call(this._context, e);

return result;
}

_validateAction(e) {
const excludeValidators = this._excludeValidators;
const { executors } = Action;

// eslint-disable-next-line no-restricted-syntax
for (const name in executors) {
if (!excludeValidators[name]) {
const executor = executors[name];
executor.validate?.(e);

if (e.cancel) {
return false;
}
}
}

return true;
}

_executeAction(e) {
let result;
const { executors } = Action;

for (const name in executors) {
const executor = executors[name];
executor.execute?.(e);

if (e.handled) {
result = e.result;
break;
}
}

return result;
}

static registerExecutor(name, executor) {
if (isPlainObject(name)) {
each(name, Action.registerExecutor);
return;
}
Action.executors[name] = executor;
}

static unregisterExecutor(...args) {
each(args, function () {
// eslint-disable-next-line @typescript-eslint/no-dynamic-delete
delete Action.executors[this];
});
}
}

Action.executors = {};

const createValidatorByTargetElement = (condition) => (e) => {
if (!e.args.length) {
return;
}

const args = e.args[0];
const element = args[e.validatingTargetName] || args.element;

if (element && condition($(element))) {
e.cancel = true;
}
};
// @ts-expect-error expect name and executor
Action.registerExecutor({
disabled: {
validate: createValidatorByTargetElement(($target) => $target.is('.dx-state-disabled, .dx-state-disabled *')),
},

readOnly: {
validate: createValidatorByTargetElement(($target) => $target.is('.dx-state-readonly, .dx-state-readonly *:not(.dx-state-independent)')),
},
undefined: {
execute: (e) => {
if (!e.action) {
e.result = undefined;
e.handled = true;
}
},
},
func: {
execute: (e) => {
if (isFunction(e.action)) {
e.result = e.action.call(e.context, e.args[0]);
e.handled = true;
}
},
},
});

export { Action };
export default Action;
157 changes: 157 additions & 0 deletions packages/devextreme/js/__internal/core/m_class.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,157 @@
import errors from '@js/core/errors';
import { isWindow } from '@js/core/utils/type';

const wrapOverridden = function (baseProto, methodName, method) {
return function () {
const prevCallBase = this.callBase;
this.callBase = baseProto[methodName];
try {
return method.apply(this, arguments);
} finally {
this.callBase = prevCallBase;
}
};
};

const clonePrototype = function (obj) {
const func = function () { };
func.prototype = obj.prototype;
// eslint-disable-next-line new-cap
return new func();
};

const redefine = function (members) {
const that = this;
let overridden;
let memberName;
let member;

if (!members) {
return that;
}

for (memberName in members) {
member = members[memberName];
overridden = typeof that.prototype[memberName] === 'function' && typeof member === 'function';
that.prototype[memberName] = overridden ? wrapOverridden(that.parent.prototype, memberName, member) : member;
}

return that;
};

const include = function (...args) {
const classObj = this;
let argument;
let name;
let i;

// NOTE: For ES6 classes. They don't have _includedCtors/_includedPostCtors
// properties and get them from the ancestor class.
const hasClassObjOwnProperty = Object.prototype.hasOwnProperty.bind(classObj);
const isES6Class = !hasClassObjOwnProperty('_includedCtors') && !hasClassObjOwnProperty('_includedPostCtors');

if (isES6Class) {
classObj._includedCtors = classObj._includedCtors.slice(0);
classObj._includedPostCtors = classObj._includedPostCtors.slice(0);
}

for (i = 0; i < args.length; i++) {
argument = args[i];
if (argument.ctor) {
classObj._includedCtors.push(argument.ctor);
}
if (argument.postCtor) {
classObj._includedPostCtors.push(argument.postCtor);
}

// eslint-disable-next-line no-restricted-syntax
for (name in argument) {
if (name === 'ctor' || name === 'postCtor' || name === 'default') {
continue;
}
/// #DEBUG
if (name in classObj.prototype) {
throw errors.Error('E0002', name);
}
/// #ENDDEBUG
classObj.prototype[name] = argument[name];
}
}

return classObj;
};

const subclassOf = function (parentClass) {
const hasParentProperty = Object.prototype.hasOwnProperty.bind(this)('parent');
const isES6Class = !hasParentProperty && this.parent;

if (isES6Class) {
const baseClass = Object.getPrototypeOf(this);

return baseClass === parentClass || baseClass.subclassOf(parentClass);
}
if (this.parent === parentClass) {
return true;
}

if (!this.parent || !this.parent.subclassOf) {
return false;
}

return this.parent.subclassOf(parentClass);
};

const abstract = function () {
throw errors.Error('E0001');
};

const classImpl = function () { };

classImpl.inherit = function (members) {
const inheritor = function (...args) {
if (!this || isWindow(this) || typeof this.constructor !== 'function') {
throw errors.Error('E0003');
}

const instance = this;
const { ctor } = instance;
const includedCtors = instance.constructor._includedCtors;
const includedPostCtors = instance.constructor._includedPostCtors;
let i;

for (i = 0; i < includedCtors.length; i++) {
includedCtors[i].call(instance);
}

if (ctor) {
ctor.apply(instance, args);
}

for (i = 0; i < includedPostCtors.length; i++) {
includedPostCtors[i].call(instance);
}
};

inheritor.prototype = clonePrototype(this);

Object.setPrototypeOf(inheritor, this);

inheritor.inherit = this.inherit;
inheritor.abstract = abstract;
inheritor.redefine = redefine;
inheritor.include = include;
inheritor.subclassOf = subclassOf;

inheritor.parent = this;
inheritor._includedCtors = this._includedCtors ? this._includedCtors.slice(0) : [];
inheritor._includedPostCtors = this._includedPostCtors ? this._includedPostCtors.slice(0) : [];
inheritor.prototype.constructor = inheritor;

inheritor.redefine(members);

return inheritor;
};

classImpl.abstract = abstract;

export default classImpl;
Loading
Loading