Skip to content

Commit 69cef98

Browse files
author
Hristo Hristov
committed
Updated prpareExtend to support JavaProxy
1 parent 8a7cbdf commit 69cef98

2 files changed

Lines changed: 105 additions & 109 deletions

File tree

src/assets/internal/prepareExtend.js

Lines changed: 0 additions & 109 deletions
This file was deleted.

src/assets/internal/ts_helpers.js

Lines changed: 105 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,105 @@
1+
(function() {
2+
var __extends_ts = function (d, b) {
3+
for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p];
4+
function __() { this.constructor = d; }
5+
__.prototype = b.prototype;
6+
d.prototype = new __();
7+
};
8+
9+
var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
10+
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") return Reflect.decorate(decorators, target, key, desc);
11+
switch (arguments.length) {
12+
case 2: return decorators.reduceRight(function(o, d) { return (d && d(o)) || o; }, target);
13+
case 3: return decorators.reduceRight(function(o, d) { return (d && d(target, key)), void 0; }, void 0);
14+
case 4: return decorators.reduceRight(function(o, d) { return (d && d(target, key, o)) || o; }, desc);
15+
}
16+
};
17+
18+
var __native = function(thiz) {
19+
var result = thiz.__proto__;
20+
21+
for (var prop in thiz)
22+
{
23+
if (thiz.hasOwnProperty(prop))
24+
{
25+
thiz.__proto__[prop] = thiz[prop];
26+
delete thiz[prop];
27+
}
28+
}
29+
30+
thiz.constructor = undefined;
31+
thiz.__proto__ = undefined;
32+
Object.freeze(thiz);
33+
Object.preventExtensions(thiz)
34+
return result;
35+
};
36+
37+
var __extends = function(Child, Parent) {
38+
39+
if (Parent.extend) {
40+
if (Parent.__isPrototypeImplementationObject) {
41+
throw new Error("Can not extend an already extended native object.");
42+
}
43+
44+
function extend(child, parent) {
45+
__log("TS extend called");
46+
if (!child.__extended) {
47+
child.__extended = parent.extend(child.name, child.prototype);
48+
}
49+
50+
return child.__extended;
51+
};
52+
53+
Parent.__activityExtend = function(parent, name, implementationObject) {
54+
__log("__activityExtend called");
55+
return parent.extend(name, implementationObject);
56+
};
57+
58+
Parent.call = function(thiz) {
59+
var Extended = extend(thiz.__proto__.__child, thiz.__proto__.__parent);
60+
if (arguments.length > 1)
61+
{
62+
thiz.__proto__ = new (Function.prototype.bind.apply(Extended, [null].concat(Array.prototype.slice.call(arguments, 1))));
63+
}
64+
else
65+
{
66+
thiz.__proto__ = new Extended();
67+
}
68+
};
69+
70+
Parent.apply = function(thiz, args) {
71+
var Extended = extend(thiz.__proto__.__child, thiz.__proto__.__parent);
72+
if (args && args.length > 0)
73+
{
74+
thiz.__proto__ = new (Function.prototype.bind.apply(Extended, [null].concat(args)));
75+
}
76+
else
77+
{
78+
thiz.__proto__ = new Extended();
79+
}
80+
};
81+
}
82+
83+
__extends_ts(Child, Parent);
84+
85+
if (Parent.extend) {
86+
Child.__isPrototypeImplementationObject = true;
87+
Child.__proto__ = Parent;
88+
Child.prototype.__parent = Parent;
89+
Child.prototype.__child = Child;
90+
}
91+
}
92+
93+
function JavaProxy(className) {
94+
return function (target) {
95+
var extended = target.extend(className, target.prototype)
96+
extended.name = className;
97+
return extended;
98+
};
99+
}
100+
101+
global.__native = __native;
102+
global.__extends = __extends;
103+
global.__decorate = __decorate;
104+
global.JavaProxy = JavaProxy;
105+
})()

0 commit comments

Comments
 (0)