|
1 | | -type OpenUI5Patcher = { |
2 | | - prototype: { |
3 | | - _mAttributes: { [key: string]: string }, |
4 | | - openEnd: () => OpenUI5Patcher, |
5 | | - } |
| 1 | +type PatcherTarget = { |
| 2 | + _mAttributes: { [key: string]: string }, |
| 3 | + openEnd: () => OpenUI5Patcher, |
6 | 4 | }; |
7 | 5 |
|
8 | | -const patchPatcher = (Patcher: OpenUI5Patcher) => { |
9 | | - const origOpenEnd = Patcher.prototype.openEnd; |
10 | | - Patcher.prototype.openEnd = function openEnd() { |
11 | | - if (this._mAttributes.popover) { |
| 6 | +type OpenUI5Patcher = { prototype: PatcherTarget } // newer versions (on prototype) |
| 7 | + | PatcherTarget; // older versions (on constructor directly) |
| 8 | + |
| 9 | +const patchOpenEnd = (target: PatcherTarget) => { |
| 10 | + const origOpenEnd = target.openEnd; |
| 11 | + target.openEnd = function openEnd() { |
| 12 | + if (this._mAttributes?.popover) { |
12 | 13 | delete this._mAttributes.popover; // The "popover" attribute will be managed externally, don't let Patcher remove it |
13 | 14 | } |
14 | 15 | return origOpenEnd.apply(this); |
15 | 16 | }; |
16 | 17 | }; |
17 | 18 |
|
| 19 | +const patchPatcher = (Patcher: OpenUI5Patcher) => { |
| 20 | + // Newer version: properties are on prototype |
| 21 | + if ("prototype" in Patcher && "openEnd" in Patcher.prototype) { |
| 22 | + patchOpenEnd(Patcher.prototype); |
| 23 | + } else if ("openEnd" in Patcher) { |
| 24 | + // Older version: properties are on constructor directly |
| 25 | + patchOpenEnd(Patcher); |
| 26 | + } |
| 27 | +}; |
| 28 | + |
18 | 29 | export default patchPatcher; |
19 | 30 | export type { OpenUI5Patcher }; |
0 commit comments