mirror of
https://github.com/konvajs/konva.git
synced 2025-10-15 12:34:52 +08:00
Some performance fixes and optimizations
This commit is contained in:
@@ -126,6 +126,7 @@ export interface NodeConfig {
|
||||
|
||||
// CONSTANTS
|
||||
var ABSOLUTE_OPACITY = 'absoluteOpacity',
|
||||
ALL_LISTENERS = 'allEventListeners',
|
||||
ABSOLUTE_TRANSFORM = 'absoluteTransform',
|
||||
ABSOLUTE_SCALE = 'absoluteScale',
|
||||
CANVAS = 'canvas',
|
||||
@@ -195,6 +196,7 @@ export abstract class Node<Config extends NodeConfig = NodeConfig> {
|
||||
} = {};
|
||||
attrs: any = {};
|
||||
index = 0;
|
||||
_allEventListeners: null | Array<Function> = null;
|
||||
parent: Container<Node> | null = null;
|
||||
_cache: Map<string, any> = new Map<string, any>();
|
||||
_attachedDepsListeners: Map<string, boolean> = new Map<string, boolean>();
|
||||
@@ -720,6 +722,7 @@ export abstract class Node<Config extends NodeConfig = NodeConfig> {
|
||||
evtStr: K,
|
||||
handler: KonvaEventListener<this, NodeEventMap[K]>
|
||||
) {
|
||||
this._cache && this._cache.delete(ALL_LISTENERS);
|
||||
if (arguments.length === 3) {
|
||||
return this._delegate.apply(this, arguments);
|
||||
}
|
||||
@@ -2276,6 +2279,11 @@ export abstract class Node<Config extends NodeConfig = NodeConfig> {
|
||||
}
|
||||
|
||||
_getListeners(eventType) {
|
||||
const events = this._cache.get(ALL_LISTENERS);
|
||||
if (events) {
|
||||
return events;
|
||||
}
|
||||
|
||||
let totalEvents = [];
|
||||
let obj;
|
||||
while (true) {
|
||||
@@ -2293,6 +2301,7 @@ export abstract class Node<Config extends NodeConfig = NodeConfig> {
|
||||
totalEvents = events.concat(totalEvents);
|
||||
obj = Object.getPrototypeOf(obj);
|
||||
}
|
||||
this._cache.set(ALL_LISTENERS, totalEvents);
|
||||
return totalEvents;
|
||||
}
|
||||
_fire(eventType, evt) {
|
||||
|
@@ -30,7 +30,7 @@ export interface CircleConfig extends ShapeConfig {
|
||||
export class Circle extends Shape<CircleConfig> {
|
||||
_sceneFunc(context) {
|
||||
context.beginPath();
|
||||
context.arc(0, 0, this.radius(), 0, Math.PI * 2, false);
|
||||
context.arc(0, 0, this.attrs.radius || 0, 0, Math.PI * 2, false);
|
||||
context.closePath();
|
||||
context.fillStrokeShape(this);
|
||||
}
|
||||
|
@@ -4,7 +4,7 @@ import { Shape, ShapeConfig } from '../Shape';
|
||||
import { _registerNode } from '../Global';
|
||||
|
||||
import { GetSet } from '../types';
|
||||
import {getNumberOrArrayOfNumbersValidator} from "../Validators";
|
||||
import { getNumberOrArrayOfNumbersValidator } from '../Validators';
|
||||
export interface RectConfig extends ShapeConfig {
|
||||
cornerRadius?: number | number[];
|
||||
}
|
||||
@@ -52,7 +52,7 @@ export class Rect extends Shape<RectConfig> {
|
||||
} else {
|
||||
topLeft = Math.min(cornerRadius[0] || 0, width / 2, height / 2);
|
||||
topRight = Math.min(cornerRadius[1] || 0, width / 2, height / 2);
|
||||
bottomRight = Math.min(cornerRadius[2] ||0, width / 2, height / 2);
|
||||
bottomRight = Math.min(cornerRadius[2] || 0, width / 2, height / 2);
|
||||
bottomLeft = Math.min(cornerRadius[3] || 0, width / 2, height / 2);
|
||||
}
|
||||
context.moveTo(topLeft, 0);
|
||||
@@ -113,6 +113,11 @@ _registerNode(Rect);
|
||||
* // top-left, top-right, bottom-right, bottom-left
|
||||
* rect.cornerRadius([0, 10, 20, 30]);
|
||||
*/
|
||||
Factory.addGetterSetter(Rect, 'cornerRadius', 0, getNumberOrArrayOfNumbersValidator(4));
|
||||
Factory.addGetterSetter(
|
||||
Rect,
|
||||
'cornerRadius',
|
||||
0,
|
||||
getNumberOrArrayOfNumbersValidator(4)
|
||||
);
|
||||
|
||||
Collection.mapMethods(Rect);
|
||||
|
Reference in New Issue
Block a user