From 7b4514acd85c044d01bd912612ace0128e53ebab Mon Sep 17 00:00:00 2001 From: Joost De Cock Date: Mon, 16 Jul 2018 20:09:12 +0200 Subject: [PATCH] :construction: Working map proxy constructor function for pointlist --- lib/part.ts | 21 ++++++++------------- lib/pointlist.ts | 35 ----------------------------------- 2 files changed, 8 insertions(+), 48 deletions(-) delete mode 100644 lib/pointlist.ts diff --git a/lib/part.ts b/lib/part.ts index 933afcea62e..b9e078a9ad6 100644 --- a/lib/part.ts +++ b/lib/part.ts @@ -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>): Point { - console.log(`getting ${key}`); +function PointProxy(id: string) { + this.id = id; + this.get = function(points, key: string, proxy: ProxyHandler>): Point { return points.get(key); - }, - set: function(points: Map, key: string, point: Point, proxy: ProxyHandler>) { - console.log(arguments); - console.log(`Args above. Setting ${key} to`, point); + }; + this.set = function(points: Map, key: string, point: Point, proxy: ProxyHandler>) { 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; diff --git a/lib/pointlist.ts b/lib/pointlist.ts deleted file mode 100644 index a7387b9f585..00000000000 --- a/lib/pointlist.ts +++ /dev/null @@ -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; -}