🚧 Working map proxy constructor function for pointlist
This commit is contained in:
parent
abca8a809d
commit
7b4514acd8
2 changed files with 8 additions and 48 deletions
21
lib/part.ts
21
lib/part.ts
|
@ -2,29 +2,24 @@ import { Point } from './point'
|
||||||
import { Path } from './path'
|
import { Path } from './path'
|
||||||
import { Snippet } from './snippet'
|
import { Snippet } from './snippet'
|
||||||
import { Attributes } from './attributes'
|
import { Attributes } from './attributes'
|
||||||
import { PointList } from './pointlist'
|
|
||||||
|
|
||||||
var pointProxy: any = {
|
function PointProxy(id: string) {
|
||||||
id: 'test',
|
this.id = id;
|
||||||
get: function(points, key: string, proxy: ProxyHandler<Map<any, any>>): Point {
|
this.get = function(points, key: string, proxy: ProxyHandler<Map<any, any>>): Point {
|
||||||
console.log(`getting ${key}`);
|
|
||||||
return points.get(key);
|
return points.get(key);
|
||||||
},
|
};
|
||||||
set: function(points: Map<string, Point>, key: string, point: Point, proxy: ProxyHandler<Map<any, any>>) {
|
this.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);
|
|
||||||
point.attributes.add('data-key', key);
|
point.attributes.add('data-key', key);
|
||||||
point.attributes.add('data-part', this.id);
|
point.attributes.add('data-part', this.id);
|
||||||
points.set(key, point);
|
points.set(key, point);
|
||||||
return true;
|
return true;
|
||||||
}
|
};
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
export class Part {
|
export class Part {
|
||||||
id: string;
|
id: string;
|
||||||
render: boolean;
|
render: boolean;
|
||||||
points = new Proxy(new Map(), pointProxy);
|
points: any;
|
||||||
paths: { [index: string]: Path; } = {};
|
paths: { [index: string]: Path; } = {};
|
||||||
snippets: { [index: string]: Snippet; } = {};
|
snippets: { [index: string]: Snippet; } = {};
|
||||||
attributes = new Attributes();
|
attributes = new Attributes();
|
||||||
|
@ -33,7 +28,7 @@ export class Part {
|
||||||
constructor(id: string) {
|
constructor(id: string) {
|
||||||
this.id = id;
|
this.id = id;
|
||||||
this.render = (id.substr(0,1) === '_') ? false : true;
|
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);
|
this.points.origin = new Point(0,0);
|
||||||
|
|
||||||
return this;
|
return this;
|
||||||
|
|
|
@ -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;
|
|
||||||
}
|
|
Loading…
Add table
Add a link
Reference in a new issue