1
0
Fork 0

🚧 Working map proxy constructor function for pointlist

This commit is contained in:
Joost De Cock 2018-07-16 20:09:12 +02:00
parent abca8a809d
commit 7b4514acd8
2 changed files with 8 additions and 48 deletions

View file

@ -2,29 +2,24 @@ import { Point } from './point'
import { Path } from './path'
import { Snippet } from './snippet'
import { Attributes } from './attributes'
import { PointList } from './pointlist'
var pointProxy: any = {
id: 'test',
get: function(points, key: string, proxy: ProxyHandler<Map<any, any>>): Point {
console.log(`getting ${key}`);
function PointProxy(id: string) {
this.id = id;
this.get = function(points, key: string, proxy: ProxyHandler<Map<any, any>>): Point {
return points.get(key);
},
set: function(points: Map<string, Point>, key: string, point: Point, proxy: ProxyHandler<Map<any, any>>) {
console.log(arguments);
console.log(`Args above. Setting ${key} to`, point);
};
this.set = function(points: Map<string, Point>, key: string, point: Point, proxy: ProxyHandler<Map<any, any>>) {
point.attributes.add('data-key', key);
point.attributes.add('data-part', this.id);
points.set(key, point);
return true;
}
};
};
export class Part {
id: string;
render: boolean;
points = new Proxy(new Map(), pointProxy);
points: any;
paths: { [index: string]: Path; } = {};
snippets: { [index: string]: Snippet; } = {};
attributes = new Attributes();
@ -33,7 +28,7 @@ export class Part {
constructor(id: string) {
this.id = id;
this.render = (id.substr(0,1) === '_') ? false : true;
this.points = new Proxy(new Map(), pointProxy);
this.points = new Proxy(new Map(), new PointProxy(id));
this.points.origin = new Point(0,0);
return this;

View file

@ -1,35 +0,0 @@
import { Point } from './point'
function pointDecorator(target: any, key: string) {
// property value
var _val: Point = this[key];
// property getter
var getter = function (): Point {
console.log(`Get: ${key} => ${_val}`);
return _val;
};
// property setter
var setter = function (newVal: Point): void {
console.log(`Set: ${key} => ${newVal}`);
_val = newVal;
};
// Delete property.
if (delete this[key]) {
// Create new property with getter and setter
Object.defineProperty(target, key, {
get: getter,
set: setter,
enumerable: true,
configurable: true
});
}
}
export class PointList {
@pointDecorator
[index: string]: Point;
}