@aurelia/runtime
Advanced tools
Comparing version 2.0.1-dev.202404041108 to 2.0.1-dev.202404170324
@@ -1,5 +0,2 @@ | ||
export { type ExpressionKind, CallFunctionExpression, CustomExpression, BindingBehaviorExpression, ValueConverterExpression, AssignExpression, ConditionalExpression, AccessThisExpression, AccessGlobalExpression, AccessScopeExpression, AccessBoundaryExpression, AccessMemberExpression, AccessKeyedExpression, CallScopeExpression, CallMemberExpression, BinaryExpression, UnaryExpression, PrimitiveLiteralExpression, ArrayLiteralExpression, ObjectLiteralExpression, TemplateExpression, TaggedTemplateExpression, ArrayBindingPattern, ObjectBindingPattern, BindingIdentifier, ForOfStatement, Interpolation, DestructuringAssignmentExpression, DestructuringAssignmentSingleExpression, DestructuringAssignmentRestExpression, ArrowFunction, astVisit, Unparser, type AnyBindingExpression, type BindingBehaviorInstance, type IsPrimary, type IsLiteral, type IsLeftHandSide, type IsUnary, type IsBinary, type IsConditional, type IsAssign, type IsValueConverter, type IsBindingBehavior, type IsAssignable, type IsExpression, type IsExpressionOrStatement, type IVisitor, type BinaryOperator, type BindingIdentifierOrPattern, type UnaryOperator, type IAstEvaluator, type ValueConverterInstance, } from './binding/ast'; | ||
export { astAssign, astBind, astEvaluate, astUnbind, } from './binding/ast.eval'; | ||
export { type IConnectableBinding, connectable, BindingObserverRecord, } from './binding/connectable'; | ||
export { IExpressionParser, type ExpressionType, parseExpression, } from './binding/expression-parser'; | ||
export { type IObserverLocatorBasedConnectable, connectable, BindingObserverRecord, } from './observation/connectable'; | ||
export { ArrayObserver, ArrayIndexObserver, enableArrayObservation, disableArrayObservation, type IArrayIndexObserver, } from './observation/array-observer'; | ||
@@ -12,5 +9,5 @@ export { MapObserver, enableMapObservation, disableMapObservation, } from './observation/map-observer'; | ||
export { IDirtyChecker, DirtyChecker, DirtyCheckProperty, DirtyCheckSettings, } from './observation/dirty-checker'; | ||
export { type IEffect, IObservation, Observation, type EffectRunFunc, } from './observation/observation'; | ||
export { type IEffect, IObservation, Observation, type EffectRunFunc, } from './observation/effect-runner'; | ||
export { type IObservableDefinition, observable, } from './observation/observable'; | ||
export { type IObjectObservationAdapter, IObserverLocator, INodeObserverLocator, getCollectionObserver, ObserverLocator, getObserverLookup, type ObservableGetter, type ObservableSetter, } from './observation/observer-locator'; | ||
export { type IObjectObservationAdapter, IObserverLocator, INodeObserverLocator, getCollectionObserver, ObserverLocator, getObserverLookup, type ObservableGetter, } from './observation/observer-locator'; | ||
export { PrimitiveObserver, } from './observation/primitive-observer'; | ||
@@ -21,7 +18,6 @@ export { PropertyAccessor, } from './observation/property-accessor'; | ||
export { SetterObserver, } from './observation/setter-observer'; | ||
export { ISignaler, } from './observation/signaler'; | ||
export { SubscriberRecord, subscriberCollection, } from './observation/subscriber-collection'; | ||
export { batch, } from './observation/subscriber-batch'; | ||
export { ConnectableSwitcher, } from './observation/connectable-switcher'; | ||
export { type AccessorOrObserver, type IRateLimitOptions, type IBinding, AccessorType, type Collection, type CollectionKind, type IAccessor, type IBindingContext, type ICollectionChangeTracker, type ICollectionObserver, type IConnectable, type ICollectionSubscriber, type IndexMap, type IObserver, type IObservable, type IOverrideContext, type InterceptorFunc, type ISubscribable, type ISubscriberCollection, type CollectionObserver, type ICollectionSubscriberCollection, type ICollectionSubscribable, type ISubscriber, type ISubscriberRecord, isIndexMap, copyIndexMap, cloneIndexMap, createIndexMap, ICoercionConfiguration, } from './observation'; | ||
export { type AccessorOrObserver, AccessorType, type Collection, type CollectionKind, type IAccessor, type IBindingContext, type ICollectionChangeTracker, type ICollectionObserver, type IConnectable, type ICollectionSubscriber, type IndexMap, type IObserver, type IObservable, type IOverrideContext, type InterceptorFunc, type ISubscribable, type ISubscriberCollection, type CollectionObserver, type ICollectionSubscriberCollection, type ICollectionSubscribable, type ISubscriber, type ISubscriberRecord, isIndexMap, copyIndexMap, cloneIndexMap, createIndexMap, ICoercionConfiguration, } from './observation'; | ||
//# sourceMappingURL=index.d.ts.map |
@@ -1,20 +0,3 @@ | ||
import { IDisposable, IIndexable, IServiceLocator } from '@aurelia/kernel'; | ||
import type { Scope } from './observation/scope'; | ||
import { IIndexable } from '@aurelia/kernel'; | ||
import type { CollectionLengthObserver, CollectionSizeObserver } from './observation/collection-length-observer'; | ||
import { TaskQueue } from '@aurelia/platform'; | ||
export interface IBinding { | ||
readonly isBound: boolean; | ||
bind(scope: Scope): void; | ||
unbind(): void; | ||
get: IServiceLocator['get']; | ||
useScope?(scope: Scope): void; | ||
limit?(opts: IRateLimitOptions): IDisposable; | ||
} | ||
export interface IRateLimitOptions { | ||
type: 'throttle' | 'debounce'; | ||
delay: number; | ||
queue: TaskQueue; | ||
now: () => number; | ||
signals: string[]; | ||
} | ||
export declare const ICoercionConfiguration: import("@aurelia/kernel").InterfaceSymbol<ICoercionConfiguration>; | ||
@@ -21,0 +4,0 @@ export interface ICoercionConfiguration { |
import { ICoercionConfiguration, IObserver, InterceptorFunc } from '../observation'; | ||
import type { AccessorType, ISubscriber, ICollectionSubscriber, ISubscriberCollection, IConnectable } from '../observation'; | ||
import type { IConnectableBinding } from '../binding/connectable'; | ||
import type { IObserverLocatorBasedConnectable } from './connectable'; | ||
import type { IObserverLocator } from './observer-locator'; | ||
export type ComputedGetterFn<T = any, R = any> = (this: T, obj: T, observer: IConnectable) => R; | ||
export interface ComputedObserver<T extends object> extends IConnectableBinding, ISubscriberCollection { | ||
export interface ComputedObserver<T extends object> extends IObserverLocatorBasedConnectable, ISubscriberCollection { | ||
} | ||
export declare class ComputedObserver<T extends object> implements IObserver, IConnectableBinding, ISubscriber, ICollectionSubscriber, ISubscriberCollection { | ||
export declare class ComputedObserver<T extends object> implements IObserver, IObserverLocatorBasedConnectable, ISubscriber, ICollectionSubscriber, ISubscriberCollection { | ||
type: AccessorType; | ||
@@ -10,0 +10,0 @@ /** |
import { AccessorType, IAccessor, ISubscriberCollection } from '../observation'; | ||
import type { Constructable } from '@aurelia/kernel'; | ||
import { type Constructable } from '@aurelia/kernel'; | ||
import type { InterceptorFunc } from '../observation'; | ||
@@ -9,8 +9,9 @@ export interface IObservableDefinition { | ||
} | ||
export declare function observable(target: object, key: PropertyKey, descriptor?: PropertyDescriptor & { | ||
initializer?: () => unknown; | ||
}): void; | ||
export declare function observable(config: IObservableDefinition): (target: Constructable | object, ...args: unknown[]) => void; | ||
export declare function observable(key: PropertyKey): ClassDecorator; | ||
export declare function observable(): PropertyDecorator; | ||
type FieldInitializer<TFThis, TValue> = (this: TFThis, initialValue: TValue) => TValue; | ||
type ObservableFieldDecorator<TFThis, TValue> = (target: undefined, context: ClassFieldDecoratorContext<TFThis, TValue>) => FieldInitializer<TFThis, TValue>; | ||
type ObservableClassDecorator<TCThis extends Constructable> = (target: TCThis, context: ClassDecoratorContext<TCThis>) => void; | ||
export declare function observable<TFThis, TValue>(target: undefined, context: ClassFieldDecoratorContext<TFThis, TValue>): FieldInitializer<TFThis, TValue>; | ||
export declare function observable<TCThis extends Constructable, TFThis, TValue>(config: IObservableDefinition): (target: TCThis | undefined, context: ClassDecoratorContext<TCThis> | ClassFieldDecoratorContext<TFThis, TValue>) => FieldInitializer<TFThis, TValue> | void; | ||
export declare function observable<TCThis extends Constructable>(key: PropertyKey): ObservableClassDecorator<TCThis>; | ||
export declare function observable<TFThis, TValue>(): ObservableFieldDecorator<TFThis, TValue>; | ||
export interface SetterNotifier extends IAccessor, ISubscriberCollection { | ||
@@ -25,2 +26,3 @@ } | ||
} | ||
export {}; | ||
//# sourceMappingURL=observable.d.ts.map |
@@ -17,12 +17,12 @@ import { ComputedGetterFn } from './computed-observer'; | ||
export declare const INodeObserverLocator: import("@aurelia/kernel").InterfaceSymbol<INodeObserverLocator>; | ||
export interface IComputedObserverLocator { | ||
getObserver(obj: object, key: PropertyKey, pd: ExtendedPropertyDescriptor, requestor: IObserverLocator): IObserver; | ||
} | ||
export declare const IComputedObserverLocator: import("@aurelia/kernel").InterfaceSymbol<IComputedObserverLocator>; | ||
export type ExtendedPropertyDescriptor = PropertyDescriptor & { | ||
get?: ObservableGetter; | ||
set?: ObservableSetter; | ||
}; | ||
export type ObservableGetter = PropertyDescriptor['get'] & { | ||
getObserver?(obj: unknown, requestor: IObserverLocator): IObserver; | ||
getObserver?(obj: unknown): IObserver; | ||
}; | ||
export type ObservableSetter = PropertyDescriptor['set'] & { | ||
getObserver?(obj: unknown, requestor: IObserverLocator): IObserver; | ||
}; | ||
export declare class ObserverLocator { | ||
@@ -29,0 +29,0 @@ addAdapter(adapter: IObjectObservationAdapter): void; |
import { Constructable } from '@aurelia/kernel'; | ||
export declare function nowrap(): (target: unknown, context: ClassDecoratorContext | ClassFieldDecoratorContext) => void; | ||
/** | ||
* A decorator to signal proxy observation shouldn't make an effort to wrap an object | ||
*/ | ||
export declare function nowrap(target: Constructable): void; | ||
export declare function nowrap(target: object, key: PropertyKey, descriptor?: PropertyDescriptor): void; | ||
export declare function nowrap(): ClassDecorator | PropertyDecorator | any; | ||
export declare function nowrap(target?: Constructable | object, key?: PropertyKey, descriptor?: PropertyDescriptor): ClassDecorator | PropertyDecorator; | ||
export declare function nowrap(target: Constructable, context: ClassDecoratorContext): void; | ||
export declare function nowrap(target: undefined, context: ClassFieldDecoratorContext): void; | ||
//# sourceMappingURL=proxy-decorators.d.ts.map |
@@ -1,2 +0,2 @@ | ||
import type { IBinding, IBindingContext, IOverrideContext } from '../observation'; | ||
import type { IBindingContext, IOverrideContext } from '../observation'; | ||
/** | ||
@@ -16,3 +16,3 @@ * A class for creating context in synthetic scope to keep the number of classes of context in scope small | ||
private constructor(); | ||
static getContext(scope: Scope, name: string, ancestor: number): IBindingContext | IOverrideContext | IBinding | undefined | null; | ||
static getContext(scope: Scope, name: string, ancestor: number): IBindingContext | IOverrideContext | undefined | null; | ||
/** | ||
@@ -19,0 +19,0 @@ * Create a new `Scope` backed by the provided `BindingContext` and a new standalone `OverrideContext`. |
@@ -0,5 +1,8 @@ | ||
import { $ClassDecorator } from '../utilities'; | ||
import type { Collection, ICollectionSubscriber, IndexMap, ISubscriber, ISubscriberRecord } from '../observation'; | ||
export type IAnySubscriber = ISubscriber | ICollectionSubscriber; | ||
export declare function subscriberCollection(): ClassDecorator; | ||
export declare function subscriberCollection(target: Function): void; | ||
export declare const subscriberCollection: { | ||
(): $ClassDecorator; | ||
(target: Function): void; | ||
}; | ||
export declare class SubscriberRecord<T extends IAnySubscriber> implements ISubscriberRecord<T> { | ||
@@ -6,0 +9,0 @@ count: number; |
@@ -1,2 +0,4 @@ | ||
export {}; | ||
import { Class } from '@aurelia/kernel'; | ||
export type $ClassDecorator = <T extends Class<unknown>>(value: T, context: ClassDecoratorContext) => void | T; | ||
export type $FieldDecorator = (value: undefined, context: ClassFieldDecoratorContext) => ((initialValue: unknown) => unknown) | void; | ||
//# sourceMappingURL=utilities.d.ts.map |
{ | ||
"name": "@aurelia/runtime", | ||
"version": "2.0.1-dev.202404041108", | ||
"version": "2.0.1-dev.202404170324", | ||
"main": "dist/cjs/index.cjs", | ||
@@ -57,5 +57,6 @@ "module": "dist/esm/index.mjs", | ||
"dependencies": { | ||
"@aurelia/kernel": "2.0.1-dev.202404041108", | ||
"@aurelia/metadata": "2.0.1-dev.202404041108", | ||
"@aurelia/platform": "2.0.1-dev.202404041108" | ||
"@aurelia/kernel": "2.0.1-dev.202404170324", | ||
"@aurelia/expression-parser": "2.0.1-dev.202404170324", | ||
"@aurelia/metadata": "2.0.1-dev.202404170324", | ||
"@aurelia/platform": "2.0.1-dev.202404170324" | ||
}, | ||
@@ -62,0 +63,0 @@ "devDependencies": { |
export { | ||
type ExpressionKind, | ||
// Ast nodes | ||
CallFunctionExpression, | ||
CustomExpression, | ||
BindingBehaviorExpression, | ||
ValueConverterExpression, | ||
AssignExpression, | ||
ConditionalExpression, | ||
AccessThisExpression, | ||
AccessGlobalExpression, | ||
AccessScopeExpression, | ||
AccessBoundaryExpression, | ||
AccessMemberExpression, | ||
AccessKeyedExpression, | ||
CallScopeExpression, | ||
CallMemberExpression, | ||
BinaryExpression, | ||
UnaryExpression, | ||
PrimitiveLiteralExpression, | ||
ArrayLiteralExpression, | ||
ObjectLiteralExpression, | ||
TemplateExpression, | ||
TaggedTemplateExpression, | ||
ArrayBindingPattern, | ||
ObjectBindingPattern, | ||
BindingIdentifier, | ||
ForOfStatement, | ||
Interpolation, | ||
DestructuringAssignmentExpression, | ||
DestructuringAssignmentSingleExpression, | ||
DestructuringAssignmentRestExpression, | ||
ArrowFunction, | ||
astVisit, | ||
Unparser, | ||
// ast typing helpers | ||
type AnyBindingExpression, | ||
type BindingBehaviorInstance, | ||
type IsPrimary, | ||
type IsLiteral, | ||
type IsLeftHandSide, | ||
type IsUnary, | ||
type IsBinary, | ||
type IsConditional, | ||
type IsAssign, | ||
type IsValueConverter, | ||
type IsBindingBehavior, | ||
type IsAssignable, | ||
type IsExpression, | ||
type IsExpressionOrStatement, | ||
type IVisitor, | ||
type BinaryOperator, | ||
type BindingIdentifierOrPattern, | ||
type UnaryOperator, | ||
type IAstEvaluator, | ||
type ValueConverterInstance, | ||
} from './binding/ast'; | ||
export { | ||
astAssign, | ||
astBind, | ||
astEvaluate, | ||
astUnbind, | ||
} from './binding/ast.eval'; | ||
export { | ||
type IConnectableBinding, | ||
type IObserverLocatorBasedConnectable, | ||
connectable, | ||
BindingObserverRecord, | ||
} from './binding/connectable'; | ||
export { | ||
IExpressionParser, | ||
type ExpressionType, | ||
parseExpression, | ||
} from './binding/expression-parser'; | ||
} from './observation/connectable'; | ||
@@ -117,3 +47,3 @@ export { | ||
type EffectRunFunc, | ||
} from './observation/observation'; | ||
} from './observation/effect-runner'; | ||
export { | ||
@@ -131,3 +61,3 @@ type IObservableDefinition, | ||
type ObservableGetter, | ||
type ObservableSetter, | ||
// type ObservableSetter, | ||
} from './observation/observer-locator'; | ||
@@ -150,5 +80,2 @@ export { | ||
export { | ||
ISignaler, | ||
} from './observation/signaler'; | ||
export { | ||
SubscriberRecord, | ||
@@ -166,4 +93,2 @@ subscriberCollection, | ||
type AccessorOrObserver, | ||
type IRateLimitOptions, | ||
type IBinding, | ||
AccessorType, | ||
@@ -170,0 +95,0 @@ type Collection, |
@@ -1,25 +0,6 @@ | ||
import { DI, IDisposable, IIndexable, IServiceLocator } from '@aurelia/kernel'; | ||
import { DI, IIndexable } from '@aurelia/kernel'; | ||
import { isArray, objectFreeze } from './utilities'; | ||
import type { Scope } from './observation/scope'; | ||
import type { CollectionLengthObserver, CollectionSizeObserver } from './observation/collection-length-observer'; | ||
import { TaskQueue } from '@aurelia/platform'; | ||
export interface IBinding { | ||
readonly isBound: boolean; | ||
bind(scope: Scope): void; | ||
unbind(): void; | ||
get: IServiceLocator['get']; | ||
useScope?(scope: Scope): void; | ||
limit?(opts: IRateLimitOptions): IDisposable; | ||
} | ||
export interface IRateLimitOptions { | ||
type: 'throttle' | 'debounce'; | ||
delay: number; | ||
queue: TaskQueue; | ||
now: () => number; | ||
signals: string[]; | ||
} | ||
export const ICoercionConfiguration = /*@__PURE__*/DI.createInterface<ICoercionConfiguration>('ICoercionConfiguration'); | ||
@@ -26,0 +7,0 @@ export interface ICoercionConfiguration { |
@@ -18,3 +18,3 @@ import { | ||
} from './subscriber-collection'; | ||
import { def, defineHiddenProp, defineMetadata, getOwnMetadata, isFunction } from '../utilities'; | ||
import { def, defineHiddenProp, defineMetadata, getMetadata, isFunction } from '../utilities'; | ||
import { addCollectionBatch, batching } from './subscriber-batch'; | ||
@@ -372,4 +372,4 @@ import { IIndexable } from '@aurelia/kernel'; | ||
// eslint-disable-next-line @typescript-eslint/strict-boolean-expressions | ||
if (!(getOwnMetadata(observationEnabledKey, Array) ?? false)) { | ||
defineMetadata(observationEnabledKey, true, Array); | ||
if (!(getMetadata(observationEnabledKey, Array) ?? false)) { | ||
defineMetadata(true, Array, observationEnabledKey); | ||
for (const method of methods) { | ||
@@ -376,0 +376,0 @@ if (proto[method].observing !== true) { |
@@ -9,3 +9,3 @@ import { | ||
import { enterConnectable, exitConnectable } from './connectable-switcher'; | ||
import { connectable } from '../binding/connectable'; | ||
import { connectable } from './connectable'; | ||
import { wrap, unwrap } from './proxy-observation'; | ||
@@ -21,3 +21,3 @@ import { areEqual, isFunction } from '../utilities'; | ||
} from '../observation'; | ||
import type { IConnectableBinding } from '../binding/connectable'; | ||
import type { IObserverLocatorBasedConnectable } from './connectable'; | ||
import type { IObserverLocator } from './observer-locator'; | ||
@@ -30,7 +30,7 @@ import { ErrorNames, createMappedError } from '../errors'; | ||
// eslint-disable-next-line @typescript-eslint/no-unused-vars | ||
export interface ComputedObserver<T extends object> extends IConnectableBinding, ISubscriberCollection { } | ||
export interface ComputedObserver<T extends object> extends IObserverLocatorBasedConnectable, ISubscriberCollection { } | ||
export class ComputedObserver<T extends object> implements | ||
IObserver, | ||
IConnectableBinding, | ||
IObserverLocatorBasedConnectable, | ||
ISubscriber, | ||
@@ -204,3 +204,3 @@ ICollectionSubscriber, | ||
connectable(ComputedObserver); | ||
connectable(ComputedObserver, null!); | ||
subscriberCollection(ComputedObserver); |
import { createIndexMap, atObserver } from '../observation'; | ||
import { CollectionSizeObserver } from './collection-length-observer'; | ||
import { subscriberCollection } from './subscriber-collection'; | ||
import { def, defineHiddenProp, defineMetadata, getOwnMetadata } from '../utilities'; | ||
import { def, defineHiddenProp, defineMetadata, getMetadata } from '../utilities'; | ||
@@ -135,4 +135,4 @@ import type { | ||
// eslint-disable-next-line @typescript-eslint/strict-boolean-expressions | ||
if (!(getOwnMetadata(observationEnabledKey, Map) ?? false)) { | ||
defineMetadata(observationEnabledKey, true, Map); | ||
if (!(getMetadata(observationEnabledKey, Map) ?? false)) { | ||
defineMetadata(true, Map, observationEnabledKey); | ||
for (const method of methods) { | ||
@@ -139,0 +139,0 @@ if (proto[method].observing !== true) { |
@@ -5,3 +5,3 @@ import { AccessorType, IAccessor, IObserver, ISubscriberCollection, atObserver } from '../observation'; | ||
import type { Constructable, IIndexable } from '@aurelia/kernel'; | ||
import { emptyObject, type Constructable, type IIndexable } from '@aurelia/kernel'; | ||
import type { IBindingContext, InterceptorFunc, IObservable } from '../observation'; | ||
@@ -31,2 +31,6 @@ import type { ObservableGetter } from './observer-locator'; | ||
type FieldInitializer<TFThis, TValue> = (this: TFThis, initialValue: TValue) => TValue; | ||
type ObservableFieldDecorator<TFThis, TValue> = (target: undefined, context: ClassFieldDecoratorContext<TFThis, TValue>) => FieldInitializer<TFThis, TValue>; | ||
type ObservableClassDecorator<TCThis extends Constructable> = (target: TCThis, context: ClassDecoratorContext<TCThis>) => void; | ||
// for | ||
@@ -36,3 +40,3 @@ // class { | ||
// } | ||
export function observable(target: object, key: PropertyKey, descriptor?: PropertyDescriptor & { initializer?: () => unknown }): void; | ||
export function observable<TFThis, TValue>(target: undefined, context: ClassFieldDecoratorContext<TFThis, TValue>): FieldInitializer<TFThis, TValue>; | ||
// for | ||
@@ -45,3 +49,3 @@ // @observable({...}) | ||
// } | ||
export function observable(config: IObservableDefinition): (target: Constructable | object, ...args: unknown[]) => void; | ||
export function observable<TCThis extends Constructable, TFThis, TValue>(config: IObservableDefinition): (target: TCThis | undefined, context: ClassDecoratorContext<TCThis> | ClassFieldDecoratorContext<TFThis, TValue>) => FieldInitializer<TFThis, TValue> | void; | ||
// for | ||
@@ -51,3 +55,3 @@ // @observable('') class {} | ||
// @observable(Symbol()) class {} | ||
export function observable(key: PropertyKey): ClassDecorator; | ||
export function observable<TCThis extends Constructable>(key: PropertyKey): ObservableClassDecorator<TCThis>; | ||
// for: | ||
@@ -57,9 +61,5 @@ // class { | ||
// } | ||
export function observable(): PropertyDecorator; | ||
export function observable<TFThis, TValue>(): ObservableFieldDecorator<TFThis, TValue>; | ||
// impl, wont be seen | ||
export function observable( | ||
targetOrConfig?: Constructable | object | PropertyKey | IObservableDefinition, | ||
key?: PropertyKey, | ||
descriptor?: PropertyDescriptor | ||
): ClassDecorator | PropertyDecorator { | ||
export function observable<TCThis extends Constructable, TFThis, TValue>(targetOrConfig?: undefined | IObservableDefinition | PropertyKey, context?: ClassFieldDecoratorContext): ObservableClassDecorator<TCThis> | ObservableFieldDecorator<TFThis, TValue> | FieldInitializer<TFThis, TValue> { | ||
if (!SetterNotifier.mixed) { | ||
@@ -69,84 +69,73 @@ SetterNotifier.mixed = true; | ||
} | ||
// either this check, or arguments.length === 3 | ||
// or could be both, so can throw against user error for better DX | ||
if (key == null) { | ||
// for: | ||
// @observable('prop') | ||
// class {} | ||
// | ||
// @observable({ name: 'prop', callback: ... }) | ||
// class {} | ||
// | ||
// class { | ||
// @observable() prop | ||
// @observable({ callback: ... }) prop2 | ||
// } | ||
return ((t: Constructable, k: PropertyKey, d: PropertyDescriptor) => deco(t, k, d, targetOrConfig as PropertyKey | IObservableDefinition)) as ClassDecorator; | ||
let isClassDecorator = false; | ||
let config: IObservableDefinition; | ||
if (typeof targetOrConfig === 'object') { | ||
config = targetOrConfig; | ||
} else if (targetOrConfig != null) { | ||
config = { name: targetOrConfig }; | ||
isClassDecorator = true; | ||
} else { | ||
config = emptyObject; | ||
} | ||
// for: | ||
// class { | ||
// @observable prop | ||
// } | ||
return deco(targetOrConfig, key, descriptor) as PropertyDecorator; | ||
function deco( | ||
target: Constructable | object | PropertyKey | undefined, | ||
key?: PropertyKey, | ||
descriptor?: PropertyDescriptor & { initializer?: CallableFunction }, | ||
config?: PropertyKey | IObservableDefinition, | ||
): void | PropertyDescriptor { | ||
// class decorator? | ||
const isClassDecorator = key === void 0; | ||
config = typeof config !== 'object' | ||
? { name: config } | ||
// eslint-disable-next-line @typescript-eslint/strict-boolean-expressions | ||
: (config || {}); | ||
// case: @observable() prop | ||
if (arguments.length === 0) { | ||
return function (target: unknown, context: DecoratorContext) { | ||
if (context.kind !== 'field') throw createMappedError(ErrorNames.invalid_observable_decorator_usage); | ||
return createFieldInitializer(context); | ||
}; | ||
} | ||
if (isClassDecorator) { | ||
key = config.name; | ||
} | ||
// case: @observable prop | ||
if (context?.kind === 'field') return createFieldInitializer(context); | ||
if (key == null || key === '') { | ||
throw createMappedError(ErrorNames.invalid_observable_decorator_usage); | ||
// case: @observable(PropertyKey) class | ||
if (isClassDecorator) { | ||
return function (target: TCThis, _context: ClassDecoratorContext<TCThis>) { | ||
createDescriptor(target, config.name!, () => noValue, true); | ||
}; | ||
} | ||
// case: @observable({...}) class | @observable({...}) prop | ||
return function (target: Constructable | undefined, context: ClassFieldDecoratorContext | ClassDecoratorContext) { | ||
switch (context.kind) { | ||
case 'field': return createFieldInitializer(context); | ||
case 'class': return createDescriptor(target, config.name!, () => noValue, true); | ||
default: throw createMappedError(ErrorNames.invalid_observable_decorator_usage); | ||
} | ||
}; | ||
// determine callback name based on config or convention. | ||
function createFieldInitializer(context: ClassFieldDecoratorContext): FieldInitializer<TFThis, TValue> { | ||
let $initialValue: TValue; | ||
context.addInitializer(function (this: unknown) { | ||
createDescriptor(this, context.name, () => $initialValue, false); | ||
}); | ||
return function (this: TFThis, initialValue: TValue) { | ||
return $initialValue = initialValue; | ||
}; | ||
} | ||
function createDescriptor(target: unknown, property: PropertyKey, initialValue: () => unknown, targetIsClass: boolean): void { | ||
// eslint-disable-next-line @typescript-eslint/prefer-nullish-coalescing, @typescript-eslint/strict-boolean-expressions | ||
const callback = config.callback || `${safeString(key)}Changed`; | ||
let initialValue = noValue; | ||
if (descriptor) { | ||
// we're adding a getter and setter which means the property descriptor | ||
// cannot have a "value" or "writable" attribute | ||
delete descriptor.value; | ||
delete descriptor.writable; | ||
initialValue = descriptor.initializer?.(); | ||
delete descriptor.initializer; | ||
} else { | ||
descriptor = { configurable: true }; | ||
} | ||
// make the accessor enumerable by default, as fields are enumerable | ||
if (!('enumerable' in descriptor)) { | ||
descriptor.enumerable = true; | ||
} | ||
// todo(bigopon/fred): discuss string api for converter | ||
const callback = config.callback || `${safeString(property)}Changed`; | ||
const $set = config.set; | ||
descriptor.get = function g(/* @observable */this: SetterObserverOwningObject) { | ||
const notifier = getNotifier(this, key!, callback, initialValue, $set); | ||
const observableGetter: ObservableGetter = function (this: SetterObserverOwningObject) { | ||
const notifier = getNotifier(this, property, callback, initialValue, $set); | ||
currentConnectable()?.subscribeTo(notifier); | ||
return notifier.getValue(); | ||
}; | ||
descriptor.set = function s(/* @observable */this: SetterObserverOwningObject, newValue: unknown) { | ||
getNotifier(this, key!, callback, initialValue, $set).setValue(newValue); | ||
observableGetter.getObserver = function (obj: SetterObserverOwningObject) { | ||
return getNotifier(obj, property, callback, initialValue, $set); | ||
}; | ||
(descriptor.get as ObservableGetter).getObserver = function gO(/* @observable */obj: SetterObserverOwningObject) { | ||
return getNotifier(obj, key!, callback, initialValue, $set); | ||
const descriptor = { | ||
enumerable: true, | ||
configurable: true, | ||
get: observableGetter, | ||
set(this: SetterObserverOwningObject, newValue: TValue) { | ||
getNotifier(this, property, callback, initialValue, $set).setValue(newValue); | ||
} | ||
}; | ||
if (isClassDecorator) { | ||
def((target as Constructable).prototype as object, key, descriptor); | ||
} else { | ||
return descriptor; | ||
} | ||
if (targetIsClass) def((target as Constructable).prototype as object, property, descriptor); | ||
else def(target as object, property, descriptor); | ||
} | ||
@@ -159,3 +148,3 @@ } | ||
callbackKey: PropertyKey, | ||
initialValue: unknown, | ||
initialValue: () => unknown, | ||
set: InterceptorFunc | undefined, | ||
@@ -166,3 +155,4 @@ ): SetterNotifier { | ||
if (notifier == null) { | ||
notifier = new SetterNotifier(obj, callbackKey, set, initialValue === noValue ? void 0 : initialValue); | ||
const $initialValue = initialValue(); | ||
notifier = new SetterNotifier(obj, callbackKey, set, $initialValue === noValue ? void 0 : $initialValue); | ||
lookup[key as string] = notifier; | ||
@@ -169,0 +159,0 @@ } |
@@ -58,12 +58,30 @@ import { Primitive, isArrayIndex, ILogger, resolve } from '@aurelia/kernel'; | ||
export interface IComputedObserverLocator { | ||
getObserver(obj: object, key: PropertyKey, pd: ExtendedPropertyDescriptor, requestor: IObserverLocator): IObserver; | ||
} | ||
export const IComputedObserverLocator = /*@__PURE__*/createInterface<IComputedObserverLocator>( | ||
'IComputedObserverLocator', | ||
x => x.singleton(class DefaultLocator implements IComputedObserverLocator { | ||
public getObserver(obj: object, key: PropertyKey, pd: ExtendedPropertyDescriptor, requestor: IObserverLocator): IObserver { | ||
const observer = new ComputedObserver(obj, pd.get!, pd.set, requestor, true); | ||
def(obj, key, { | ||
enumerable: pd.enumerable, | ||
configurable: true, | ||
get: objectAssign(((/* Computed Observer */) => observer.getValue()) as ObservableGetter, { getObserver: () => observer }), | ||
set: (/* Computed Observer */v) => { | ||
observer.setValue(v); | ||
}, | ||
}); | ||
return observer; | ||
} | ||
}) | ||
); | ||
export type ExtendedPropertyDescriptor = PropertyDescriptor & { | ||
get?: ObservableGetter; | ||
set?: ObservableSetter; | ||
}; | ||
export type ObservableGetter = PropertyDescriptor['get'] & { | ||
getObserver?(obj: unknown, requestor: IObserverLocator): IObserver; | ||
getObserver?(obj: unknown): IObserver; | ||
}; | ||
export type ObservableSetter = PropertyDescriptor['set'] & { | ||
getObserver?(obj: unknown, requestor: IObserverLocator): IObserver; | ||
}; | ||
@@ -74,2 +92,3 @@ export class ObserverLocator { | ||
/** @internal */ private readonly _nodeObserverLocator = resolve(INodeObserverLocator); | ||
/** @internal */ private readonly _computedObserverLocator = resolve(IComputedObserverLocator); | ||
@@ -170,3 +189,3 @@ public addAdapter(adapter: IObjectObservationAdapter): void { | ||
if (obs == null) { | ||
obs = (pd.get?.getObserver ?? pd.set?.getObserver)?.(obj, this); | ||
obs = (pd.get?.getObserver)?.(obj); | ||
} | ||
@@ -177,3 +196,4 @@ | ||
? pd.configurable | ||
? this._createComputedObserver(obj, key, pd, true) | ||
// ? this._createComputedObserver(obj, key, pd, true) | ||
? this._computedObserverLocator.getObserver(obj, key, pd, this) | ||
: this._dirtyChecker.createProperty(obj, key) | ||
@@ -188,16 +208,16 @@ : obs; | ||
/** @internal */ | ||
private _createComputedObserver(obj: object, key: PropertyKey, pd: PropertyDescriptor, useProxy?: boolean) { | ||
const observer = new ComputedObserver(obj, pd.get!, pd.set, this, !!useProxy); | ||
def(obj, key, { | ||
enumerable: pd.enumerable, | ||
configurable: true, | ||
get: objectAssign(((/* Computed Observer */) => observer.getValue()) as ObservableGetter, { getObserver: () => observer }), | ||
set: (/* Computed Observer */v) => { | ||
observer.setValue(v); | ||
}, | ||
}); | ||
// /** @internal */ | ||
// private _createComputedObserver(obj: object, key: PropertyKey, pd: PropertyDescriptor, useProxy?: boolean) { | ||
// const observer = new ComputedObserver(obj, pd.get!, pd.set, this, !!useProxy); | ||
// def(obj, key, { | ||
// enumerable: pd.enumerable, | ||
// configurable: true, | ||
// get: objectAssign(((/* Computed Observer */) => observer.getValue()) as ObservableGetter, { getObserver: () => observer }), | ||
// set: (/* Computed Observer */v) => { | ||
// observer.setValue(v); | ||
// }, | ||
// }); | ||
return observer; | ||
} | ||
// return observer; | ||
// } | ||
@@ -204,0 +224,0 @@ /** @internal */ |
@@ -1,5 +0,6 @@ | ||
import { Constructable } from '@aurelia/kernel'; | ||
import { Class, Constructable } from '@aurelia/kernel'; | ||
import { defineHiddenProp, safeString } from '../utilities'; | ||
import { nowrapClassKey, nowrapPropKey } from './proxy-observation'; | ||
export function nowrap(): (target: unknown, context: ClassDecoratorContext | ClassFieldDecoratorContext) => void; | ||
/** | ||
@@ -11,4 +12,3 @@ * A decorator to signal proxy observation shouldn't make an effort to wrap an object | ||
// class {} | ||
export function nowrap(target: Constructable): void; | ||
export function nowrap(target: Constructable, context: ClassDecoratorContext): void; | ||
// for | ||
@@ -18,55 +18,31 @@ // class { | ||
// } | ||
export function nowrap(target: object, key: PropertyKey, descriptor?: PropertyDescriptor): void; | ||
// for | ||
// @nowrap() | ||
// class {} | ||
// or | ||
// class { @nowrap() prop } | ||
// returning any just for TS, as it is unable to selectively choose whether it's a class decorator or prop decorator | ||
// eslint-disable-next-line @typescript-eslint/no-explicit-any, @typescript-eslint/no-redundant-type-constituents | ||
export function nowrap(): ClassDecorator | PropertyDecorator | any; // (target: Constructable | object, key: PropertyKey, descriptor?: PropertyDescriptor) => void; | ||
// base signature | ||
export function nowrap( | ||
target?: Constructable | object, | ||
key?: PropertyKey, | ||
descriptor?: PropertyDescriptor | ||
): ClassDecorator | PropertyDecorator; | ||
export function nowrap(target: undefined, context: ClassFieldDecoratorContext): void; | ||
/** | ||
* A decorator to signal proxy observation shouldn't make an effort to wrap an object | ||
*/ | ||
export function nowrap( | ||
target?: Constructable | object, | ||
key?: PropertyKey | ||
): void | ClassDecorator | PropertyDecorator { | ||
if (target == null) { | ||
// for | ||
// @nowrap() | ||
// class {} | ||
// or | ||
// class { @nowrap() prop } | ||
return (t: Constructable | object, k?: PropertyKey) => deco(t, k); | ||
} else { | ||
// for | ||
// @nowrap | ||
// class {} | ||
// or | ||
// class { | ||
// @nowrap prop | ||
// } | ||
return deco(target, key); | ||
} | ||
export function nowrap< | ||
TThis extends object | ||
>( | ||
target?: Class<TThis> | undefined, | ||
context?: ClassDecoratorContext<Class<TThis>> | ClassFieldDecoratorContext<TThis> | ||
): void | ||
| ((target: unknown, context: ClassDecoratorContext | ClassFieldDecoratorContext) => void) { | ||
return arguments.length === 0 ? decorator : decorator(target!, context!); | ||
function deco( | ||
target: Constructable | object, | ||
key?: PropertyKey | ||
): void | ClassDecorator | PropertyDecorator { | ||
// eslint-disable-next-line @typescript-eslint/strict-boolean-expressions | ||
const isClassDecorator = !key; | ||
if (isClassDecorator) { | ||
defineHiddenProp(target, nowrapClassKey, true); | ||
} else { | ||
// defining on the constructor means inheritance lookup is supported | ||
defineHiddenProp((target as object).constructor, `${nowrapPropKey}_${safeString(key)}__`, true); | ||
function decorator( | ||
target: unknown, | ||
context: ClassDecoratorContext<Class<TThis>> | ClassFieldDecoratorContext<TThis> | ||
): void { | ||
switch (context.kind) { | ||
case 'class': | ||
defineHiddenProp(target as Class<TThis>, nowrapClassKey, true); | ||
break; | ||
case 'field': | ||
context.addInitializer(function (this: object) { | ||
const target = this.constructor; | ||
const property = `${nowrapPropKey}_${safeString(context.name)}__`; | ||
if (property in target) return; | ||
defineHiddenProp(target, property, true); | ||
}); | ||
break; | ||
} | ||
@@ -84,11 +60,8 @@ } | ||
class MyModel2 {} | ||
class MyModel3 { | ||
@nowrap public prop = 1; | ||
@nowrap() public prop1 = 1; | ||
} | ||
class MyModel4 { | ||
@nowrap() public prop = 2; | ||
} | ||
} | ||
/* eslint-enable */ |
import { ErrorNames, createMappedError } from '../errors'; | ||
import type { IBinding, IBindingContext, IOverrideContext } from '../observation'; | ||
import type { IBindingContext, IOverrideContext } from '../observation'; | ||
@@ -27,3 +27,3 @@ /** | ||
public static getContext(scope: Scope, name: string, ancestor: number): IBindingContext | IOverrideContext | IBinding | undefined | null { | ||
public static getContext(scope: Scope, name: string, ancestor: number): IBindingContext | IOverrideContext | undefined | null { | ||
if (scope == null) { | ||
@@ -30,0 +30,0 @@ throw createMappedError(ErrorNames.null_scope); |
import { createIndexMap, type AccessorType, type ICollectionSubscriberCollection, type ICollectionObserver, atObserver } from '../observation'; | ||
import { CollectionSizeObserver } from './collection-length-observer'; | ||
import { subscriberCollection } from './subscriber-collection'; | ||
import { def, defineHiddenProp, defineMetadata, getOwnMetadata } from '../utilities'; | ||
import { def, defineHiddenProp, defineMetadata, getMetadata } from '../utilities'; | ||
import { batching, addCollectionBatch } from './subscriber-batch'; | ||
@@ -115,4 +115,4 @@ import { IIndexable } from '@aurelia/kernel'; | ||
// eslint-disable-next-line @typescript-eslint/strict-boolean-expressions | ||
if (!(getOwnMetadata(observationEnabledKey, Set) ?? false)) { | ||
defineMetadata(observationEnabledKey, true, Set); | ||
if (!(getMetadata(observationEnabledKey, Set) ?? false)) { | ||
defineMetadata(true, Set, observationEnabledKey); | ||
for (const method of methods) { | ||
@@ -119,0 +119,0 @@ if (proto[method].observing !== true) { |
@@ -1,2 +0,2 @@ | ||
import { def, defineHiddenProp, ensureProto } from '../utilities'; | ||
import { $ClassDecorator, def, defineHiddenProp, ensureProto } from '../utilities'; | ||
@@ -16,24 +16,41 @@ import type { | ||
/* eslint-disable @typescript-eslint/ban-types */ | ||
export function subscriberCollection(): ClassDecorator; | ||
export function subscriberCollection(target: Function): void; | ||
export function subscriberCollection(target?: Function): ClassDecorator | void { | ||
return target == null ? subscriberCollectionDeco : subscriberCollectionDeco(target); | ||
} | ||
export const subscriberCollection = (() => { | ||
const decoratedTarget = new WeakSet<Function>(); | ||
function subscriberCollectionDeco(target: Function): void { // ClassDecorator expects it to be derived from Function | ||
if (decoratedTarget.has(target)) { | ||
return; | ||
function subscriberCollection(): $ClassDecorator; | ||
function subscriberCollection(target: Function): void; | ||
function subscriberCollection(target?: Function): $ClassDecorator | void { | ||
return target == null ? subscriberCollectionDeco : subscriberCollectionDeco(target); | ||
} | ||
decoratedTarget.add(target); | ||
const proto = target.prototype as ISubscriberCollection; | ||
// not configurable, as in devtool, the getter could be invoked on the prototype, | ||
// and become permanently broken | ||
def(proto, 'subs', { get: getSubscriberRecord }); | ||
ensureProto(proto, 'subscribe', addSubscriber); | ||
ensureProto(proto, 'unsubscribe', removeSubscriber); | ||
} | ||
/* eslint-enable @typescript-eslint/ban-types */ | ||
function getSubscriberRecord(this: ISubscriberCollection) { | ||
return defineHiddenProp(this, 'subs', new SubscriberRecord()); | ||
} | ||
function addSubscriber(this: ISubscriberCollection, subscriber: IAnySubscriber): boolean { | ||
return this.subs.add(subscriber as ISubscriber & ICollectionSubscriber); | ||
} | ||
function removeSubscriber(this: ISubscriberCollection, subscriber: IAnySubscriber): boolean { | ||
return this.subs.remove(subscriber as ISubscriber & ICollectionSubscriber); | ||
} | ||
const decoratedTarget = new WeakSet<Function>(); | ||
function subscriberCollectionDeco(target: Function): void { // ClassDecorator expects it to be derived from Function | ||
if (decoratedTarget.has(target)) { | ||
return; | ||
} | ||
decoratedTarget.add(target); | ||
const proto = target.prototype as ISubscriberCollection; | ||
// not configurable, as in devtool, the getter could be invoked on the prototype, | ||
// and become permanently broken | ||
def(proto, 'subs', { get: getSubscriberRecord }); | ||
ensureProto(proto, 'subscribe', addSubscriber); | ||
ensureProto(proto, 'unsubscribe', removeSubscriber); | ||
} | ||
/* eslint-enable @typescript-eslint/ban-types */ | ||
return subscriberCollection; | ||
})(); | ||
export class SubscriberRecord<T extends IAnySubscriber> implements ISubscriberRecord<T> { | ||
@@ -94,13 +111,1 @@ public count: number = 0; | ||
} | ||
function getSubscriberRecord(this: ISubscriberCollection) { | ||
return defineHiddenProp(this, 'subs', new SubscriberRecord()); | ||
} | ||
function addSubscriber(this: ISubscriberCollection, subscriber: IAnySubscriber): boolean { | ||
return this.subs.add(subscriber as ISubscriber & ICollectionSubscriber); | ||
} | ||
function removeSubscriber(this: ISubscriberCollection, subscriber: IAnySubscriber): boolean { | ||
return this.subs.remove(subscriber as ISubscriber & ICollectionSubscriber); | ||
} |
import { Metadata } from '@aurelia/metadata'; | ||
import { DI } from '@aurelia/kernel'; | ||
import { Class, DI } from '@aurelia/kernel'; | ||
export type $ClassDecorator = <T extends Class<unknown>>(value: T, context: ClassDecoratorContext) => void | T; | ||
export type $FieldDecorator = (value: undefined, context: ClassFieldDecoratorContext) => ((initialValue: unknown) => unknown) | void; | ||
const O = Object; | ||
@@ -76,4 +79,3 @@ | ||
/** @internal */ export const getOwnMetadata = Metadata.getOwn; | ||
/** @internal */ export const hasOwnMetadata = Metadata.hasOwn; | ||
/** @internal */ export const getMetadata = Metadata.get; | ||
/** @internal */ export const defineMetadata = Metadata.define; |
Sorry, the diff of this file is too big to display
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
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
1161098
4
92
20405
+ Added@aurelia/expression-parser@2.0.1-dev.202404170324(transitive)
+ Added@aurelia/kernel@2.0.1-dev.202404170324(transitive)
+ Added@aurelia/metadata@2.0.1-dev.202404170324(transitive)
+ Added@aurelia/platform@2.0.1-dev.202404170324(transitive)
- Removed@aurelia/kernel@2.0.1-dev.202404041108(transitive)
- Removed@aurelia/metadata@2.0.1-dev.202404041108(transitive)
- Removed@aurelia/platform@2.0.1-dev.202404041108(transitive)