@leafer/decorator 1.4.2 → 1.5.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.4.2",
3
+ "version": "1.5.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.4.2",
26
- "@leafer/data": "1.4.2",
27
- "@leafer/debug": "1.4.2"
25
+ "@leafer/platform": "1.5.0",
26
+ "@leafer/data": "1.5.0",
27
+ "@leafer/debug": "1.5.0"
28
28
  },
29
29
  "devDependencies": {
30
- "@leafer/interface": "1.4.2"
30
+ "@leafer/interface": "1.5.0"
31
31
  }
32
32
  }
package/src/data.ts CHANGED
@@ -1,5 +1,4 @@
1
- import { ILeafData, ILeaf, IObject, IValue, ILeafAttrDescriptor, ILeafAttrDescriptorFn } from '@leafer/interface'
2
- import { DataHelper } from '@leafer/data'
1
+ import { ILeafData, ILeaf, IObject, IValue, ILeafAttrDescriptor, ILeafAttrDescriptorFn, IValueFunction } from '@leafer/interface'
3
2
  import { Debug } from '@leafer/debug'
4
3
 
5
4
  import { defineKey, getDescriptor } from './object'
@@ -255,7 +254,7 @@ function getSetMethodName(key: string): string {
255
254
 
256
255
 
257
256
  // define leaf.__[key] getter/setter
258
- export function defineDataProcessor(target: ILeaf, key: string, defaultValue?: IValue): void {
257
+ export function defineDataProcessor(target: ILeaf, key: string, defaultValue?: IValue | IValueFunction): void {
259
258
 
260
259
  const data = target.__DataProcessor.prototype
261
260
  const computedKey = '_' + key
@@ -273,11 +272,10 @@ export function defineDataProcessor(target: ILeaf, key: string, defaultValue?: I
273
272
 
274
273
  if (defaultValue === undefined) {
275
274
  property.get = function () { return this[computedKey] }
276
- } else if (typeof defaultValue === 'object') {
277
- const { clone } = DataHelper
275
+ } else if (typeof defaultValue === 'function') {
278
276
  property.get = function () {
279
277
  let v = this[computedKey]
280
- if (v === undefined) this[computedKey] = v = clone(defaultValue)
278
+ if (v === undefined) this[computedKey] = v = defaultValue((this as ILeafData).__leaf)
281
279
  return v
282
280
  }
283
281
  }
package/types/index.d.ts CHANGED
@@ -1,4 +1,4 @@
1
- import { ILeaf, IValue, ILeafAttrDescriptor, ILeafAttrDescriptorFn, IObject, IFunction } from '@leafer/interface';
1
+ import { ILeaf, IValue, ILeafAttrDescriptor, ILeafAttrDescriptorFn, IObject, IValueFunction, IFunction } from '@leafer/interface';
2
2
 
3
3
  declare function decorateLeafAttr(defaultValue?: IValue, descriptorFn?: ILeafAttrDescriptorFn): (target: ILeaf, key: string) => void;
4
4
  declare function attr(partDescriptor?: ILeafAttrDescriptor): ILeafAttrDescriptor;
@@ -27,7 +27,7 @@ declare function hitType(defaultValue?: IValue): (target: ILeaf, key: string) =>
27
27
  declare function cursorType(defaultValue?: IValue): (target: ILeaf, key: string) => void;
28
28
  declare function dataProcessor(processor: IObject): (target: IObject, _key?: string) => void;
29
29
  declare function layoutProcessor(processor: IObject): (target: IObject, _key?: string) => void;
30
- declare function defineDataProcessor(target: ILeaf, key: string, defaultValue?: IValue): void;
30
+ declare function defineDataProcessor(target: ILeaf, key: string, defaultValue?: IValue | IValueFunction): void;
31
31
 
32
32
  declare function rewrite(method: IFunction): (target: IObject, key: string) => void;
33
33
  declare function rewriteAble(): (_target: IObject) => void;