mirror of
https://github.com/konvajs/konva.git
synced 2025-06-27 21:54:37 +08:00
better let const var variable
This commit is contained in:
parent
4eddaf813d
commit
9f5a7f0e2d
33
src/Node.ts
33
src/Node.ts
@ -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);
|
||||
}
|
||||
}
|
||||
|
11
src/Shape.ts
11
src/Shape.ts
@ -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);
|
||||
|
@ -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 {
|
||||
|
Loading…
Reference in New Issue
Block a user