source: imaps-frontend/node_modules/konva/lib/Factory.js@ 0c6b92a

main
Last change on this file since 0c6b92a was 0c6b92a, checked in by stefan toskovski <stefantoska84@…>, 5 weeks ago

Pred finalna verzija

  • Property mode set to 100644
File size: 5.1 KB
RevLine 
[d565449]1"use strict";
2Object.defineProperty(exports, "__esModule", { value: true });
3exports.Factory = void 0;
4const Util_1 = require("./Util");
5const Validators_1 = require("./Validators");
[0c6b92a]6const GET = 'get', SET = 'set';
[d565449]7exports.Factory = {
8 addGetterSetter(constructor, attr, def, validator, after) {
9 exports.Factory.addGetter(constructor, attr, def);
10 exports.Factory.addSetter(constructor, attr, validator, after);
11 exports.Factory.addOverloadedGetterSetter(constructor, attr);
12 },
13 addGetter(constructor, attr, def) {
[0c6b92a]14 const method = GET + Util_1.Util._capitalize(attr);
[d565449]15 constructor.prototype[method] =
16 constructor.prototype[method] ||
17 function () {
[0c6b92a]18 const val = this.attrs[attr];
[d565449]19 return val === undefined ? def : val;
20 };
21 },
22 addSetter(constructor, attr, validator, after) {
[0c6b92a]23 const method = SET + Util_1.Util._capitalize(attr);
[d565449]24 if (!constructor.prototype[method]) {
25 exports.Factory.overWriteSetter(constructor, attr, validator, after);
26 }
27 },
28 overWriteSetter(constructor, attr, validator, after) {
[0c6b92a]29 const method = SET + Util_1.Util._capitalize(attr);
[d565449]30 constructor.prototype[method] = function (val) {
31 if (validator && val !== undefined && val !== null) {
32 val = validator.call(this, val, attr);
33 }
34 this._setAttr(attr, val);
35 if (after) {
36 after.call(this);
37 }
38 return this;
39 };
40 },
41 addComponentsGetterSetter(constructor, attr, components, validator, after) {
[0c6b92a]42 let len = components.length, capitalize = Util_1.Util._capitalize, getter = GET + capitalize(attr), setter = SET + capitalize(attr), n, component;
[d565449]43 constructor.prototype[getter] = function () {
[0c6b92a]44 const ret = {};
[d565449]45 for (n = 0; n < len; n++) {
46 component = components[n];
47 ret[component] = this.getAttr(attr + capitalize(component));
48 }
49 return ret;
50 };
[0c6b92a]51 const basicValidator = (0, Validators_1.getComponentValidator)(components);
[d565449]52 constructor.prototype[setter] = function (val) {
[0c6b92a]53 let oldVal = this.attrs[attr], key;
[d565449]54 if (validator) {
55 val = validator.call(this, val);
56 }
57 if (basicValidator) {
58 basicValidator.call(this, val, attr);
59 }
60 for (key in val) {
61 if (!val.hasOwnProperty(key)) {
62 continue;
63 }
64 this._setAttr(attr + capitalize(key), val[key]);
65 }
66 if (!val) {
67 components.forEach((component) => {
68 this._setAttr(attr + capitalize(component), undefined);
69 });
70 }
71 this._fireChangeEvent(attr, oldVal, val);
72 if (after) {
73 after.call(this);
74 }
75 return this;
76 };
77 exports.Factory.addOverloadedGetterSetter(constructor, attr);
78 },
79 addOverloadedGetterSetter(constructor, attr) {
[0c6b92a]80 const capitalizedAttr = Util_1.Util._capitalize(attr), setter = SET + capitalizedAttr, getter = GET + capitalizedAttr;
[d565449]81 constructor.prototype[attr] = function () {
82 if (arguments.length) {
83 this[setter](arguments[0]);
84 return this;
85 }
86 return this[getter]();
87 };
88 },
89 addDeprecatedGetterSetter(constructor, attr, def, validator) {
90 Util_1.Util.error('Adding deprecated ' + attr);
[0c6b92a]91 const method = GET + Util_1.Util._capitalize(attr);
92 const message = attr +
[d565449]93 ' property is deprecated and will be removed soon. Look at Konva change log for more information.';
94 constructor.prototype[method] = function () {
95 Util_1.Util.error(message);
[0c6b92a]96 const val = this.attrs[attr];
[d565449]97 return val === undefined ? def : val;
98 };
99 exports.Factory.addSetter(constructor, attr, validator, function () {
100 Util_1.Util.error(message);
101 });
102 exports.Factory.addOverloadedGetterSetter(constructor, attr);
103 },
104 backCompat(constructor, methods) {
105 Util_1.Util.each(methods, function (oldMethodName, newMethodName) {
[0c6b92a]106 const method = constructor.prototype[newMethodName];
107 const oldGetter = GET + Util_1.Util._capitalize(oldMethodName);
108 const oldSetter = SET + Util_1.Util._capitalize(oldMethodName);
[d565449]109 function deprecated() {
110 method.apply(this, arguments);
111 Util_1.Util.error('"' +
112 oldMethodName +
113 '" method is deprecated and will be removed soon. Use ""' +
114 newMethodName +
115 '" instead.');
116 }
117 constructor.prototype[oldMethodName] = deprecated;
118 constructor.prototype[oldGetter] = deprecated;
119 constructor.prototype[oldSetter] = deprecated;
120 });
121 },
122 afterSetFilter() {
123 this._filterUpToDate = false;
124 },
125};
Note: See TracBrowser for help on using the repository browser.