@formily/shared
Advanced tools
Comparing version 1.1.7 to 2.0.0-beta.0
{ | ||
"name": "@formily/shared", | ||
"version": "1.1.7", | ||
"version": "2.0.0-beta.0", | ||
"license": "MIT", | ||
@@ -21,3 +21,3 @@ "main": "lib", | ||
}, | ||
"gitHead": "d712d3a7d28fad2e5a95b324c3bf0c865b52e01b", | ||
"gitHead": "edf8f5b38d7c128501d01151729a85a7ca9ef132", | ||
"scripts": { | ||
@@ -24,0 +24,0 @@ "build": "tsc --declaration" |
import { each } from './array' | ||
import { isValid } from './isEmpty' | ||
export const defaults = (...args: any[]): any => { | ||
const result = {} | ||
each(args, target => { | ||
each(target, (value, key) => { | ||
if (isValid(value)) { | ||
result[key] = value | ||
import { isPlainObj, isArr, getType } from './types' | ||
import { BigData } from './big-data' | ||
const isUnNormalObject = (value: any) => { | ||
if (value?._owner || value?.$$typeof) { | ||
return true | ||
} | ||
if (value?._isAMomentObject || value?._isJSONSchemaObject) { | ||
return true | ||
} | ||
if (value?.toJS || value?.toJSON) { | ||
return true | ||
} | ||
} | ||
const isPlainValue = (val: any) => { | ||
if (isUnNormalObject(val)) { | ||
return false | ||
} | ||
if (BigData.isBigData(val)) { | ||
return false | ||
} | ||
return isPlainObj(val) || isArr(val) | ||
} | ||
/** | ||
* | ||
* @param defaults | ||
* @param targets | ||
*/ | ||
export const defaults = (defaults_: any, targets: any) => { | ||
if ( | ||
getType(defaults_) !== getType(targets) || | ||
!isPlainValue(defaults_) || | ||
!isPlainValue(targets) | ||
) { | ||
return isValid(targets) ? targets : defaults_ | ||
} else { | ||
const results = isPlainObj(defaults_) ? {} : [] | ||
each(targets, (value, key) => { | ||
results[key] = defaults(defaults_[key], value) | ||
}) | ||
each(defaults_, (value, key) => { | ||
if (!isValid(results[key])) { | ||
results[key] = value | ||
} | ||
}) | ||
}) | ||
return result | ||
return results | ||
} | ||
} |
@@ -29,3 +29,3 @@ import { isFn, Subscriber, Subscription } from './types' | ||
notify = (payload?: Payload) => { | ||
notify = (payload?: Payload, silent?: boolean) => { | ||
if (this.subscription) { | ||
@@ -38,2 +38,3 @@ if (this.subscription && isFn(this.subscription.notify)) { | ||
} | ||
if (silent) return | ||
const filter = (payload: Payload) => { | ||
@@ -40,0 +41,0 @@ if (this.subscription && isFn(this.subscription.filter)) { |
const isType = <T>(type: string | string[]) => (obj: unknown): obj is T => | ||
obj != null && | ||
(Array.isArray(type) ? type : [type]).some( | ||
t => Object.prototype.toString.call(obj) === `[object ${t}]` | ||
t => getType(obj) === `[object ${t}]` | ||
) | ||
export const getType = (obj: any) => Object.prototype.toString.call(obj) | ||
export const isFn = isType<(...args: any[]) => any>([ | ||
@@ -7,0 +8,0 @@ 'Function', |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
Deprecated
MaintenanceThe maintainer of the package marked it as deprecated. This could indicate that a single version should not be used, or that the package is no longer maintained and any new vulnerabilities will not be fixed.
Found 1 instance in 1 package
No v1
QualityPackage is not semver >=1. This means it is not stable and does not support ^ ranges.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
70796
2222
1
1