@leafer/decorator 1.7.0 → 1.8.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@leafer/decorator",
3
- "version": "1.7.0",
3
+ "version": "1.8.0",
4
4
  "description": "@leafer/decorator",
5
5
  "author": "Chao (Leafer) Wan",
6
6
  "license": "MIT",
@@ -22,11 +22,11 @@
22
22
  "leaferjs"
23
23
  ],
24
24
  "dependencies": {
25
- "@leafer/platform": "1.7.0",
26
- "@leafer/data": "1.7.0",
27
- "@leafer/debug": "1.7.0"
25
+ "@leafer/platform": "1.8.0",
26
+ "@leafer/data": "1.8.0",
27
+ "@leafer/debug": "1.8.0"
28
28
  },
29
29
  "devDependencies": {
30
- "@leafer/interface": "1.7.0"
30
+ "@leafer/interface": "1.8.0"
31
31
  }
32
32
  }
package/src/data.ts CHANGED
@@ -2,7 +2,7 @@ import { ILeafData, ILeaf, IObject, IValue, ILeafAttrDescriptor, ILeafAttrDescri
2
2
  import { DataHelper, isEmptyData } from '@leafer/data'
3
3
  import { Debug } from '@leafer/debug'
4
4
 
5
- import { defineKey, getDescriptor } from './object'
5
+ import { defineKey, getDescriptor, createDescriptor } from './object'
6
6
 
7
7
 
8
8
  // name
@@ -264,15 +264,7 @@ export function defineDataProcessor(target: ILeaf, key: string, defaultValue?: I
264
264
  const computedKey = '_' + key
265
265
  const setMethodName = getSetMethodName(key)
266
266
 
267
- const property: IObject & ThisType<ILeafData> = {
268
- get() {
269
- const v = (this as IObject)[computedKey]
270
- return v === undefined ? defaultValue : v
271
- },
272
- set(value: IValue) {
273
- (this as IObject)[computedKey] = value
274
- }
275
- }
267
+ const property: IObject & ThisType<ILeafData> = createDescriptor(key, defaultValue)
276
268
 
277
269
  if (defaultValue === undefined) {
278
270
  property.get = function () { return this[computedKey] }
package/src/index.ts CHANGED
@@ -1,4 +1,4 @@
1
1
  export { defineLeafAttr, decorateLeafAttr, attr, dataType, positionType, autoLayoutType, boundsType, doBoundsType, naturalBoundsType, affectStrokeBoundsType, doStrokeType, strokeType, affectRenderBoundsType, scaleType, rotationType, surfaceType, opacityType, visibleType, sortType, maskType, eraserType, hitType, pathType, pathInputType, cursorType, dataProcessor, layoutProcessor, defineDataProcessor } from './data'
2
2
  export { useModule, rewrite, rewriteAble } from './rewrite'
3
- export { defineKey, getDescriptor } from './object'
3
+ export { defineKey, getDescriptor, createDescriptor } from './object'
4
4
  export { registerUI, registerUIEvent } from './class'
package/src/object.ts CHANGED
@@ -1,4 +1,4 @@
1
- import { IObject } from '@leafer/interface'
1
+ import { IObject, IValue } from '@leafer/interface'
2
2
 
3
3
  export function defineKey<T>(target: T, key: string, descriptor: IObject & ThisType<T>, noConfigurable?: boolean): void {
4
4
  if (!noConfigurable) descriptor.configurable = descriptor.enumerable = true
@@ -9,6 +9,14 @@ export function getDescriptor(object: IObject, name: string) {
9
9
  return Object.getOwnPropertyDescriptor(object, name)
10
10
  }
11
11
 
12
+ export function createDescriptor(key: string, defaultValue?: IValue) {
13
+ const privateKey = '_' + key
14
+ return {
15
+ get() { const v = (this as IObject)[privateKey]; return v === undefined ? defaultValue : v },
16
+ set(value: IValue) { (this as IObject)[privateKey] = value }
17
+ }
18
+ }
19
+
12
20
  export function getNames(object: IObject): string[] {
13
21
  return Object.getOwnPropertyNames(object)
14
22
  }
package/types/index.d.ts CHANGED
@@ -35,8 +35,12 @@ declare function useModule(module: IObject, exclude?: string[]): (target: IObjec
35
35
 
36
36
  declare function defineKey<T>(target: T, key: string, descriptor: IObject & ThisType<T>, noConfigurable?: boolean): void;
37
37
  declare function getDescriptor(object: IObject, name: string): PropertyDescriptor;
38
+ declare function createDescriptor(key: string, defaultValue?: IValue): {
39
+ get(): any;
40
+ set(value: IValue): void;
41
+ };
38
42
 
39
43
  declare function registerUI(): (target: IObject) => void;
40
44
  declare function registerUIEvent(): (target: IObject) => void;
41
45
 
42
- export { affectRenderBoundsType, affectStrokeBoundsType, attr, autoLayoutType, boundsType, cursorType, dataProcessor, dataType, decorateLeafAttr, defineDataProcessor, defineKey, defineLeafAttr, doBoundsType, doStrokeType, eraserType, getDescriptor, hitType, layoutProcessor, maskType, naturalBoundsType, opacityType, pathInputType, pathType, positionType, registerUI, registerUIEvent, rewrite, rewriteAble, rotationType, scaleType, sortType, strokeType, surfaceType, useModule, visibleType };
46
+ export { affectRenderBoundsType, affectStrokeBoundsType, attr, autoLayoutType, boundsType, createDescriptor, cursorType, dataProcessor, dataType, decorateLeafAttr, defineDataProcessor, defineKey, defineLeafAttr, doBoundsType, doStrokeType, eraserType, getDescriptor, hitType, layoutProcessor, maskType, naturalBoundsType, opacityType, pathInputType, pathType, positionType, registerUI, registerUIEvent, rewrite, rewriteAble, rotationType, scaleType, sortType, strokeType, surfaceType, useModule, visibleType };