@leafer/decorator 1.8.0 → 1.9.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.8.0",
3
+ "version": "1.9.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.8.0",
26
- "@leafer/data": "1.8.0",
27
- "@leafer/debug": "1.8.0"
25
+ "@leafer/platform": "1.9.0",
26
+ "@leafer/data": "1.9.0",
27
+ "@leafer/debug": "1.9.0"
28
28
  },
29
29
  "devDependencies": {
30
- "@leafer/interface": "1.8.0"
30
+ "@leafer/interface": "1.9.0"
31
31
  }
32
32
  }
package/src/data.ts CHANGED
@@ -1,5 +1,5 @@
1
1
  import { ILeafData, ILeaf, IObject, IValue, ILeafAttrDescriptor, ILeafAttrDescriptorFn, IValueFunction } from '@leafer/interface'
2
- import { DataHelper, isEmptyData } from '@leafer/data'
2
+ import { DataHelper, isEmptyData, isObject, isUndefined } from '@leafer/data'
3
3
  import { Debug } from '@leafer/debug'
4
4
 
5
5
  import { defineKey, getDescriptor, createDescriptor } from './object'
@@ -266,14 +266,14 @@ export function defineDataProcessor(target: ILeaf, key: string, defaultValue?: I
266
266
 
267
267
  const property: IObject & ThisType<ILeafData> = createDescriptor(key, defaultValue)
268
268
 
269
- if (defaultValue === undefined) {
269
+ if (isUndefined(defaultValue)) {
270
270
  property.get = function () { return this[computedKey] }
271
271
  } else if (typeof defaultValue === 'function') {
272
272
  property.get = function () {
273
273
  let v = this[computedKey]
274
274
  return v === undefined ? defaultValue((this as ILeafData).__leaf) : v
275
275
  }
276
- } else if (typeof defaultValue === 'object') {
276
+ } else if (isObject(defaultValue)) {
277
277
  const isEmpty = isEmptyData(defaultValue)
278
278
  property.get = function () {
279
279
  let v = this[computedKey]
package/src/object.ts CHANGED
@@ -1,4 +1,5 @@
1
1
  import { IObject, IValue } from '@leafer/interface'
2
+ import { isUndefined } from '@leafer/data'
2
3
 
3
4
  export function defineKey<T>(target: T, key: string, descriptor: IObject & ThisType<T>, noConfigurable?: boolean): void {
4
5
  if (!noConfigurable) descriptor.configurable = descriptor.enumerable = true
@@ -12,7 +13,7 @@ export function getDescriptor(object: IObject, name: string) {
12
13
  export function createDescriptor(key: string, defaultValue?: IValue) {
13
14
  const privateKey = '_' + key
14
15
  return {
15
- get() { const v = (this as IObject)[privateKey]; return v === undefined ? defaultValue : v },
16
+ get() { const v = (this as IObject)[privateKey]; return isUndefined(v) ? defaultValue : v },
16
17
  set(value: IValue) { (this as IObject)[privateKey] = value }
17
18
  }
18
19
  }