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

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

Update repo after prototype presentation

  • Property mode set to 100644
File size: 5.0 KB
Line 
1"use strict";
2Object.defineProperty(exports, "__esModule", { value: true });
3exports.Factory = void 0;
4const Util_1 = require("./Util");
5const Validators_1 = require("./Validators");
6var GET = 'get', SET = 'set';
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) {
14 var method = GET + Util_1.Util._capitalize(attr);
15 constructor.prototype[method] =
16 constructor.prototype[method] ||
17 function () {
18 var val = this.attrs[attr];
19 return val === undefined ? def : val;
20 };
21 },
22 addSetter(constructor, attr, validator, after) {
23 var method = SET + Util_1.Util._capitalize(attr);
24 if (!constructor.prototype[method]) {
25 exports.Factory.overWriteSetter(constructor, attr, validator, after);
26 }
27 },
28 overWriteSetter(constructor, attr, validator, after) {
29 var method = SET + Util_1.Util._capitalize(attr);
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) {
42 var len = components.length, capitalize = Util_1.Util._capitalize, getter = GET + capitalize(attr), setter = SET + capitalize(attr), n, component;
43 constructor.prototype[getter] = function () {
44 var ret = {};
45 for (n = 0; n < len; n++) {
46 component = components[n];
47 ret[component] = this.getAttr(attr + capitalize(component));
48 }
49 return ret;
50 };
51 var basicValidator = (0, Validators_1.getComponentValidator)(components);
52 constructor.prototype[setter] = function (val) {
53 var oldVal = this.attrs[attr], key;
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) {
80 var capitalizedAttr = Util_1.Util._capitalize(attr), setter = SET + capitalizedAttr, getter = GET + capitalizedAttr;
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);
91 var method = GET + Util_1.Util._capitalize(attr);
92 var message = attr +
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);
96 var val = this.attrs[attr];
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) {
106 var method = constructor.prototype[newMethodName];
107 var oldGetter = GET + Util_1.Util._capitalize(oldMethodName);
108 var oldSetter = SET + Util_1.Util._capitalize(oldMethodName);
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.