@produck/charon-options
Advanced tools
Comparing version 0.1.1 to 0.2.0
{ | ||
"name": "@produck/charon-options", | ||
"version": "0.1.1", | ||
"version": "0.2.0", | ||
"description": "Reactive options accessor provider.", | ||
@@ -38,3 +38,3 @@ "keywords": [ | ||
}, | ||
"gitHead": "7f589c264ffa8f5cb6c846f709a3cefab83dcefd" | ||
"gitHead": "281fe20e7dc0c3f6b1da4c3bb17270379828fae4" | ||
} |
@@ -5,2 +5,3 @@ import { Object, Lang, Console } from '@produck/charon'; | ||
const map = new WeakMap(); | ||
const constructorSet = new WeakSet(); | ||
const _ = getter => map.get(getter); | ||
@@ -10,5 +11,15 @@ | ||
const assertAccessorConstructor = (any, name) => { | ||
if (!constructorSet.has(any)) { | ||
Lang.throwError(`Invalid child Accessor name="${name}".`); | ||
} | ||
}; | ||
export const define = (descriptor = {}, childAccessorMap = {}) => { | ||
const finalDescriptor = Property.normalize(descriptor); | ||
for (const name in childAccessorMap) { | ||
assertAccessorConstructor(childAccessorMap[name], name); | ||
} | ||
function Raw() { | ||
@@ -37,2 +48,11 @@ const raw = {}; | ||
static appendChild(name, ChildAccessor) { | ||
if (childAccessorMap[name]) { | ||
Lang.throwError('Conflict child accessor property name.'); | ||
} | ||
assertAccessorConstructor(ChildAccessor, name); | ||
childAccessorMap[name] = ChildAccessor; | ||
} | ||
static merge(accessor, source) { | ||
@@ -55,2 +75,4 @@ if (!Lang.instanceOf(accessor, CustomAccessor)) { | ||
constructorSet.add(CustomAccessor); | ||
for (const propertyName in finalDescriptor) { | ||
@@ -57,0 +79,0 @@ Object.defineProperty(CustomAccessor.prototype, propertyName, { |
interface BaseAccessor {} | ||
interface AccessorConstructor< | ||
export interface AccessorConstructor< | ||
Descriptor extends BaseDescriptor = {}, | ||
@@ -13,2 +13,4 @@ ChildrenAccessorConstructorMap extends AccessorConstructorMap = {}, | ||
appendChild(name: string, ChildAccessor: AccessorConstructor): void; | ||
merge( | ||
@@ -41,4 +43,4 @@ accessor: MixinedAccessor<Descriptor, ChildrenAccessorConstructorMap>, | ||
type MixinedAccessor< | ||
Descriptor extends BaseDescriptor = BaseDescriptor, | ||
ChildrenAccessorConstructorMap extends AccessorConstructorMap = AccessorConstructorMap | ||
Descriptor extends BaseDescriptor = {}, | ||
ChildrenAccessorConstructorMap extends AccessorConstructorMap = {} | ||
> = BaseAccessor & { | ||
@@ -53,8 +55,14 @@ [SelfProperty in keyof Descriptor]: | ||
export function define< | ||
CustomDescriptor extends BaseDescriptor = BaseDescriptor, | ||
ChildrenAccessorConstructorMap extends AccessorConstructorMap = AccessorConstructorMap | ||
>( | ||
descriptor?: CustomDescriptor, | ||
children?: ChildrenAccessorConstructorMap | ||
): AccessorConstructor<CustomDescriptor, ChildrenAccessorConstructorMap>; | ||
export interface OptionsConstructorProvider< | ||
Context = any | ||
> { | ||
< | ||
CustomDescriptor extends BaseDescriptor = {}, | ||
ChildrenAccessorConstructorMap extends AccessorConstructorMap = {} | ||
> ( | ||
descriptor?: CustomDescriptor, | ||
children?: ChildrenAccessorConstructorMap | ||
): AccessorConstructor<CustomDescriptor, ChildrenAccessorConstructorMap>; | ||
} | ||
export const define: OptionsConstructorProvider; |
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
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
7354
156