Merge pull request #1905 from tbo47/master

refactor const let
This commit is contained in:
Anton Lavrenov 2025-03-28 14:19:03 -05:00 committed by GitHub
commit fe80a44407
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
4 changed files with 24 additions and 34 deletions

View File

@ -693,39 +693,32 @@ export abstract class Node<Config extends NodeConfig = NodeConfig> {
evtStr: K,
handler: KonvaEventListener<this, NodeEventMap[K]>
) {
this._cache && this._cache.delete(ALL_LISTENERS);
if (this._cache) {
this._cache.delete(ALL_LISTENERS);
}
if (arguments.length === 3) {
return this._delegate.apply(this, arguments as any);
}
let events = (evtStr as string).split(SPACE),
len = events.length,
n,
event,
parts,
baseEvent,
name;
const events = (evtStr as string).split(SPACE);
/*
* loop through types and attach event listeners to
* each one. eg. 'click mouseover.namespace mouseout'
* will create three event bindings
*/
for (n = 0; n < len; n++) {
event = events[n];
parts = event.split('.');
baseEvent = parts[0];
name = parts[1] || '';
for (let n = 0; n < events.length; n++) {
const event = events[n];
const parts = event.split('.');
const baseEvent = parts[0];
const name = parts[1] || '';
// create events array if it doesn't exist
if (!this.eventListeners[baseEvent]) {
this.eventListeners[baseEvent] = [];
}
this.eventListeners[baseEvent].push({
name: name,
handler: handler,
});
this.eventListeners[baseEvent].push({ name , handler });
}
return this;
@ -2208,7 +2201,7 @@ export abstract class Node<Config extends NodeConfig = NodeConfig> {
* node.addName('selected');
* node.name(); // return 'red selected'
*/
addName(name) {
addName(name: string) {
if (!this.hasName(name)) {
const oldName = this.name();
const newName = oldName ? oldName + ' ' + name : name;
@ -2380,7 +2373,7 @@ export abstract class Node<Config extends NodeConfig = NodeConfig> {
const topListeners = this._getProtoListeners(eventType);
if (topListeners) {
for (var i = 0; i < topListeners.length; i++) {
for (let i = 0; i < topListeners.length; i++) {
topListeners[i].handler.call(this, evt);
}
}
@ -2389,7 +2382,7 @@ export abstract class Node<Config extends NodeConfig = NodeConfig> {
// because events can be added/removed while firing
const selfListeners = this.eventListeners[eventType];
if (selfListeners) {
for (var i = 0; i < selfListeners.length; i++) {
for (let i = 0; i < selfListeners.length; i++) {
selfListeners[i].handler.call(this, evt);
}
}

View File

@ -594,13 +594,12 @@ export class Shape<
// 3 - when node is cached and we need to draw it into layer
const layer = this.getLayer();
let canvas = can || layer!.getCanvas(),
const canvas = can || layer!.getCanvas(),
context = canvas.getContext() as SceneContext,
cachedCanvas = this._getCanvasCache(),
drawFunc = this.getSceneFunc(),
hasShadow = this.hasShadow(),
stage,
bufferContext;
hasShadow = this.hasShadow();
let stage, bufferContext;
const skipBuffer = canvas.isCache;
const cachingSelf = top === this;
@ -633,7 +632,7 @@ export class Shape<
bufferContext.save();
bufferContext._applyLineJoin(this);
// layer might be undefined if we are using cache before adding to layer
var o = this.getAbsoluteTransform(top).getMatrix();
const o = this.getAbsoluteTransform(top).getMatrix();
bufferContext.transform(o[0], o[1], o[2], o[3], o[4], o[5]);
drawFunc.call(this, bufferContext, this);
@ -651,7 +650,7 @@ export class Shape<
context._applyLineJoin(this);
if (!cachingSelf) {
var o = this.getAbsoluteTransform(top).getMatrix();
const o = this.getAbsoluteTransform(top).getMatrix();
context.transform(o[0], o[1], o[2], o[3], o[4], o[5]);
context._applyOpacity(this);
context._applyGlobalCompositeOperation(this);

View File

@ -214,11 +214,11 @@ export class Stage extends Container<Layer> {
*/
setContainer(container) {
if (typeof container === STRING) {
let id;
if (container.charAt(0) === '.') {
const className = container.slice(1);
container = document.getElementsByClassName(className)[0];
} else {
var id;
if (container.charAt(0) !== '#') {
id = container;
} else {

View File

@ -102,26 +102,24 @@ export class Line<
}
_sceneFunc(context: Context) {
let points = this.points(),
const points = this.points(),
length = points.length,
tension = this.tension(),
closed = this.closed(),
bezier = this.bezier(),
tp,
len,
n;
bezier = this.bezier();
if (!length) {
return;
}
let n = 0;
context.beginPath();
context.moveTo(points[0], points[1]);
// tension
if (tension !== 0 && length > 4) {
tp = this.getTensionPoints();
len = tp.length;
const tp = this.getTensionPoints();
const len = tp.length;
n = closed ? 0 : 4;
if (!closed) {