Skip to content

Instantly share code, notes, and snippets.

@mmichlin66
mmichlin66 / primitive-types-proxy-and-decorator.ts
Last active October 24, 2022 09:07
Virtualizing TypeScript Properties with Proxy and Decorator - listing 6
// @virtual decorator function
function virtual( target: any, name: string)
{
// symbol to keep the proxy handler value
let sym = Symbol( name + "_proxy_handler");
Object.defineProperty( target, name, {
enumerable: true,
get()
@mmichlin66
mmichlin66 / virtualizing-numbers.ts
Last active October 15, 2020 01:59
Virtualizing TypeScript Properties with Proxy and Decorator - listing 5
class Base
{
@virtual a = 1;
b = this.a;
}
class Derived extends Base
{
a = 2;
}
@mmichlin66
mmichlin66 / proxy-and-decorator.ts
Last active October 15, 2020 01:59
Virtualizing TypeScript Properties with Proxy and Decorator - listing 4
export function virtual( target: any, name: string)
{
// symbol to keep the proxy handler value
let sym = Symbol( name + "_proxy_handler");
Object.defineProperty( target, name, {
enumerable: true,
get()
{
@mmichlin66
mmichlin66 / virtualizing-with-proxy.ts
Last active October 15, 2020 02:00
Virtualizing TypeScript Properties with Proxy and Decorator - listing 3
class VirtHandler
{
target: any;
get( t: any, p: PropertyKey, r: any): any
{
return this.target[p];
}
}
@mmichlin66
mmichlin66 / virtualizing-with-function.ts
Last active October 15, 2020 02:00
Virtualizing ypesScript Class Properties with Proxy and Decorator - listing 2
class Base
{
first = { v: 1 };
second = () => this.first;
}
class Derived extends Base
{
first = { v: 2 };
}
@mmichlin66
mmichlin66 / virtualizing-problem.ts
Last active October 15, 2020 02:00
Virtualizing TypeScript Properties with Proxy and Decorator - listing 1
class Base
{
first = { v: 1 };
second = this.first;
}
class Derived extends Base
{
first = { v: 2 };
}