Skip to content

Commit

Permalink
refactor(bindings): move binding infra to runtime html (#1944)
Browse files Browse the repository at this point in the history
BREAKING CHANGE: move various exports into the right package [skip ci]

- move astEvaluate/astAssign/astBind/astUnbind to runtime-html
- move ISignaler to runtime-html (it does not affect applications, since they are supposed to be importing from aurelia package`
- move IBinding & IRateLimitOptions type to runtime-html
- move BindingBehaviorInstance & ValueConverterInstance type to runtime-html
- renamed IConnectableBinding -> IObserverLocatorBasedConnectable, this is more accurate and less bloated
  • Loading branch information
bigopon committed Apr 17, 2024
1 parent 7e8c12f commit 1c7608a
Show file tree
Hide file tree
Showing 80 changed files with 1,162 additions and 1,110 deletions.
2 changes: 1 addition & 1 deletion packages/__e2e__/i18n/src/plugins/sut-i18n.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { I18N, Signals } from '@aurelia/i18n';
import { ISignaler } from '@aurelia/runtime';
import { ISignaler } from '@aurelia/runtime-html';
import { customElement } from '@aurelia/runtime-html';
import { Locale } from './translation-resources';
import { resolve } from '@aurelia/kernel';
Expand Down
7 changes: 4 additions & 3 deletions packages/__tests__/src/2-runtime/ast.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,8 @@ import {
Unparser,
AccessBoundaryExpression,
} from '@aurelia/expression-parser';
import { IAstEvaluator, IConnectableBinding, Scope, astAssign, astEvaluate, astBind } from '@aurelia/runtime';
import { IObserverLocatorBasedConnectable, Scope } from '@aurelia/runtime';
import { type IAstEvaluator, astAssign, astEvaluate, astBind, IBinding } from '@aurelia/runtime-html';

const $false = PrimitiveLiteralExpression.$false;
const $true = PrimitiveLiteralExpression.$true;
Expand All @@ -62,11 +63,11 @@ const dummyLocatorThatReturnsNull = {
const dummyBinding = {
observe: () => { return; },
locator: dummyLocator
} as unknown as IConnectableBinding;
} as unknown as IBinding & IObserverLocatorBasedConnectable;
const dummyBindingWithLocatorThatReturnsNull = {
observe: () => { return; },
locator: dummyLocatorThatReturnsNull,
} as unknown as IConnectableBinding;
} as unknown as IBinding & IObserverLocatorBasedConnectable;
const dummyScope = Scope.create({});

function assignDoesNotThrow(inputs: [string, IsBindingBehavior][]) {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
import { resolve } from '@aurelia/kernel';
import { BindingBehaviorInstance, Scope, IBinding } from '@aurelia/runtime';
import { Scope } from '@aurelia/runtime';
import {
type BindingBehaviorInstance,
type IBinding,
bindingBehavior,
alias,
bindable,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import { TestContext, assert, createFixture } from '@aurelia/testing';
import { BindingMode, customElement, bindable, Aurelia } from '@aurelia/runtime-html';
import { BindingMode, customElement, bindable, Aurelia, ISignaler } from '@aurelia/runtime-html';
import { delegateSyntax } from '@aurelia/compat-v1';
import { ISignaler } from '@aurelia/runtime';

async function wait(ms: number): Promise<void> {
await new Promise(resolve => setTimeout(resolve, ms));
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import { DI } from '@aurelia/kernel';
import { AccessMemberExpression, AccessScopeExpression } from '@aurelia/expression-parser';
import { astEvaluate } from '@aurelia/runtime';
import { ComputedWatcher, ExpressionWatcher } from '@aurelia/runtime-html';
import { astEvaluate, ComputedWatcher, ExpressionWatcher } from '@aurelia/runtime-html';
import { assert, createObserverLocator, createScopeForTest } from '@aurelia/testing';

describe('3-runtime-html/decorator-watch.unit.spec.ts', function () {
Expand Down
4 changes: 3 additions & 1 deletion packages/__tests__/src/3-runtime-html/promise.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,10 @@ import {
Class,
resolve,
} from '@aurelia/kernel';
import { BindingBehaviorInstance, Scope, IBinding } from '@aurelia/runtime';
import { Scope } from '@aurelia/runtime';
import {
type BindingBehaviorInstance,
type IBinding,
valueConverter,
bindingBehavior,
ValueConverter,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import { ConsoleSink, LoggerConfiguration, LogLevel, resolve } from '@aurelia/kernel';
import { ISignaler } from '@aurelia/runtime';
import { customElement, valueConverter, Aurelia, ValueConverter } from '@aurelia/runtime-html';
import { ISignaler, customElement, valueConverter, Aurelia, ValueConverter } from '@aurelia/runtime-html';
import { assert, createFixture, TestContext } from '@aurelia/testing';

describe('3-runtime-html/signaler.integration.spec.ts', function () {
Expand Down
4 changes: 2 additions & 2 deletions packages/__tests__/src/3-runtime-html/switch.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,12 +12,12 @@ import {
sink,
} from '@aurelia/kernel';
import {
BindingBehaviorInstance,
IBinding,
Scope,
} from '@aurelia/runtime';
import {
AuSlot,
type BindingBehaviorInstance,
type IBinding,
Case,
Controller,
bindingBehavior,
Expand Down
8 changes: 2 additions & 6 deletions packages/__tests__/src/3-runtime-html/with.spec.ts
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
import { assert, createFixture } from '@aurelia/testing';

describe('3-runtime-html/with.spec.ts', function () {
it('works with static scope', async function () {
it('works with static scope', function () {
const template = `Application name: \${name}
<div with.bind="contract">
Contact name: <input value.bind="name">
Contact address: <input value.bind="address">
</div>`;
const { ctx, appHost, component, startPromise, tearDown } = createFixture(
const { ctx, appHost, component } = createFixture(
template,
class App {
public name = 'Contract editor';
Expand All @@ -18,8 +18,6 @@ describe('3-runtime-html/with.spec.ts', function () {
}
);

await startPromise;

assert.includes(appHost.textContent, 'Application name: Contract editor');
const [input1, input2] = Array.from(appHost.querySelectorAll('input'));

Expand All @@ -29,8 +27,6 @@ describe('3-runtime-html/with.spec.ts', function () {
input1.value = 'name-11';
input1.dispatchEvent(new ctx.Event('change'));
assert.strictEqual(component.contract.name, 'name-11');

await tearDown();
});

it('works with dynamic scope', async function () {
Expand Down
3 changes: 2 additions & 1 deletion packages/__tests__/src/i18n/i18n.spec.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
import { I18N, I18nInitOptions, Signals } from '@aurelia/i18n';
import { EventAggregator } from '@aurelia/kernel';
import { ISignaler, nowrap } from '@aurelia/runtime';
import { nowrap } from '@aurelia/runtime';
import { assert, MockSignaler, createFixture } from '@aurelia/testing';
import { ISignaler } from '@aurelia/runtime-html';
import i18next, { PostProcessorModule } from 'i18next';
import { Spy } from '../Spy.js';
import { createI18NContainer } from './util.js';
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import { I18N, I18nConfiguration, Signals } from '@aurelia/i18n';
import { Class, IContainer } from '@aurelia/kernel';
import { ISignaler } from '@aurelia/runtime';
import { Aurelia, bindable, customElement, INode, IPlatform } from '@aurelia/runtime-html';
import { ISignaler, Aurelia, bindable, customElement, INode, IPlatform } from '@aurelia/runtime-html';
import { assert, PLATFORM, TestContext } from '@aurelia/testing';
import { createSpecFunction, TestExecutionContext, TestFunction } from '../../util.js';

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,9 @@ import { DI } from '@aurelia/kernel';
import { IExpressionParser } from '@aurelia/expression-parser';
import {
IObserverLocator,
IBinding,
} from '@aurelia/runtime';
import {
IBinding,
IRenderer,
StandardConfiguration,
IHydratableController,
Expand Down
2 changes: 1 addition & 1 deletion packages/__tests__/src/i18n/t/translation-renderer.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,10 @@ import {
import { Constructable } from '@aurelia/kernel';
import { IExpressionParser } from '@aurelia/expression-parser';
import {
IBinding,
IObserverLocator,
} from '@aurelia/runtime';
import {
IBinding,
AttributePattern,
AttributePatternDefinition,
AttrSyntax,
Expand Down
2 changes: 1 addition & 1 deletion packages/__tests__/src/i18n/util.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { I18nConfiguration, I18nInitOptions, II18nextWrapper } from '@aurelia/i18n';
import { DI, EventAggregator, IContainer, IEventAggregator, Registration } from '@aurelia/kernel';
import { ISignaler } from '@aurelia/runtime';
import { ISignaler } from '@aurelia/runtime-html';
import { MockSignaler } from '@aurelia/testing';

export interface I18nConfiguration {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,12 @@ import { DI, IServiceLocator, newInstanceForScope, newInstanceOf, Registration,
import { Unparser } from '@aurelia/expression-parser';
import {
ArrayObserver,
BindingBehaviorInstance,
IBinding,
IObserverLocator,
Scope,
} from '@aurelia/runtime';
import {
type BindingBehaviorInstance,
type IBinding,
bindable,
bindingBehavior,
customAttribute,
Expand Down
3 changes: 1 addition & 2 deletions packages/__tests__/src/validation-i18n/localization.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,7 @@ import {
ValidationMessageProvider,
} from '@aurelia/validation';
import { Unparser } from '@aurelia/expression-parser';
import { IBinding } from '@aurelia/runtime';
import { CustomElement, INode, Aurelia, IPlatform } from '@aurelia/runtime-html';
import { IBinding, CustomElement, INode, Aurelia, IPlatform } from '@aurelia/runtime-html';
import {
BindingWithBehavior,
IValidationController,
Expand Down
2 changes: 1 addition & 1 deletion packages/__tests__/src/validation/rule-provider.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,8 @@ import {
} from '@aurelia/expression-parser';
import {
Scope,
astEvaluate
} from '@aurelia/runtime';
import { astEvaluate } from '@aurelia/runtime-html';
import { assert, TestContext } from '@aurelia/testing';
import {
EqualsRule,
Expand Down
35 changes: 11 additions & 24 deletions packages/aurelia/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -248,25 +248,8 @@ export {

// SetterObserver,

ISignaler,

subscriberCollection,

type BindingBehaviorInstance,
// PartialBindingBehaviorDefinition,
// BindingBehaviorKind,
// BindingBehaviorDecorator,
// BindingBehaviorInstance,
// BindingBehaviorType,

// BindingModeBehavior,
// OneTimeBindingBehavior,
// ToViewBindingBehavior,
// FromViewBindingBehavior,
// TwoWayBindingBehavior,

// DebounceBindingBehavior,

// SignalableBinding,
// SignalBindingBehavior,

Expand Down Expand Up @@ -313,22 +296,24 @@ export {
// ICollectionChangeTracker,
// ICollectionSubscriber,

// ValueConverterDefinition,
// PartialValueConverterDefinition,
// ValueConverterKind,
// ValueConverterDecorator,
type ValueConverterInstance,
// ValueConverterType,
type IndexMap,

} from '@aurelia/runtime';

export {
// BindingBehaviorDefinition,
// PartialBindingBehaviorDefinition,
// BindingBehaviorKind,
// BindingBehaviorDecorator,
// BindingBehaviorInstance,
// BindingBehaviorType,
type BindingBehaviorInstance,

// ValueConverterDefinition,
// PartialValueConverterDefinition,
// ValueConverterKind,
// ValueConverterDecorator,
// ValueConverterType,
type ValueConverterInstance,

// BindingModeBehavior,
// OneTimeBindingBehavior,
Expand Down Expand Up @@ -696,4 +681,6 @@ export {
IModifiedEventHandlerCreator,
IEventModifier,
type IModifiedEventHandler,

ISignaler,
} from '@aurelia/runtime-html';
2 changes: 1 addition & 1 deletion packages/compat-v1/src/compat-ast.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ import {
astBind,
astEvaluate,
astUnbind,
} from '@aurelia/runtime';
} from '@aurelia/runtime-html';

let defined = false;
export function defineAstMethods() {
Expand Down
23 changes: 20 additions & 3 deletions packages/compat-v1/src/compat-call.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,23 @@
import { camelCase, type IContainer, type IServiceLocator } from '@aurelia/kernel';
import { astBind, astEvaluate, astUnbind, IAccessor, IAstEvaluator, IBinding, IConnectableBinding, IObserverLocator, Scope } from '@aurelia/runtime';
import { BindingCommandInstance, ICommandBuildInfo, IController, IHydratableController, IInstruction, IRenderer, mixinAstEvaluator, mixinUseScope, mixingBindingLimited, renderer, IPlatform } from '@aurelia/runtime-html';
import { IAccessor, IObserverLocator, IObserverLocatorBasedConnectable, Scope } from '@aurelia/runtime';
import {
astBind,
astEvaluate,
astUnbind,
type BindingCommandInstance,
ICommandBuildInfo,
IController,
IHydratableController,
IInstruction,
IRenderer,
mixinAstEvaluator,
mixinUseScope,
mixingBindingLimited,
renderer,
IPlatform,
type IAstEvaluator,
type IBinding,
} from '@aurelia/runtime-html';
import { ensureExpression, etIsFunction } from './utilities';
import { BindingCommandStaticAuDefinition } from '@aurelia/runtime-html/dist/types/resources/binding-command';
import { IExpressionParser, IsBindingBehavior } from '@aurelia/expression-parser';
Expand Down Expand Up @@ -76,7 +93,7 @@ function getTarget(potentialTarget: object): object {
/**
* A binding for handling .call syntax
*/
export interface CallBinding extends IAstEvaluator, IConnectableBinding { }
export interface CallBinding extends IAstEvaluator, IObserverLocatorBasedConnectable, IServiceLocator { }
export class CallBinding implements IBinding {
public isBound: boolean = false;

Expand Down
27 changes: 24 additions & 3 deletions packages/compat-v1/src/compat-event.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,27 @@
import { DI, IContainer, resolve } from '@aurelia/kernel';
import { astBind, astEvaluate, astUnbind, IAstEvaluator, IBinding, IConnectableBinding, Scope } from '@aurelia/runtime';
import { AppTask, BindingCommandInstance, ICommandBuildInfo, IEventTarget, IHydratableController, IInstruction, InstructionType, IRenderer, mixinAstEvaluator, mixinUseScope, mixingBindingLimited, renderer, IPlatform, IListenerBindingOptions, BindingCommandStaticAuDefinition } from '@aurelia/runtime-html';
import { IObserverLocatorBasedConnectable, type Scope } from '@aurelia/runtime';
import {
AppTask,
type BindingCommandInstance,
type ICommandBuildInfo,
IEventTarget,
type IHydratableController,
IInstruction,
InstructionType,
IRenderer,
mixinAstEvaluator,
mixinUseScope,
mixingBindingLimited,
renderer,
IPlatform,
IListenerBindingOptions,
type BindingCommandStaticAuDefinition,
astBind,
astEvaluate,
astUnbind,
type IAstEvaluator,
type IBinding,
} from '@aurelia/runtime-html';
import { createLookup, ensureExpression, etIsFunction, isFunction } from './utilities';
import { IExpressionParser, IsBindingBehavior } from '@aurelia/expression-parser';

Expand Down Expand Up @@ -93,7 +114,7 @@ export class DelegateListenerOptions {
) { }
}

export interface DelegateListenerBinding extends IAstEvaluator, IConnectableBinding { }
export interface DelegateListenerBinding extends IAstEvaluator, IObserverLocatorBasedConnectable, IServiceLocator { }
/**
* Listener binding. Handle event binding between view and view model
*/
Expand Down
4 changes: 2 additions & 2 deletions packages/i18n/src/df/date-format-binding-behavior.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import type { BindingBehaviorInstance, Scope } from '@aurelia/runtime';
import { type Scope } from '@aurelia/runtime';
import { type BindingWithBehavior, createIntlFormatValueConverterExpression, ValueConverters, behaviorTypeName } from '../utils';

import { type BindingBehaviorStaticAuDefinition } from '@aurelia/runtime-html';
import { type BindingBehaviorStaticAuDefinition, type BindingBehaviorInstance, } from '@aurelia/runtime-html';

export class DateFormatBindingBehavior implements BindingBehaviorInstance {
public static readonly $au: BindingBehaviorStaticAuDefinition = {
Expand Down
4 changes: 2 additions & 2 deletions packages/i18n/src/df/date-format-value-converter.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import { ValueConverterStaticAuDefinition } from '@aurelia/runtime-html';
import { type ValueConverterInstance, type ValueConverterStaticAuDefinition } from '@aurelia/runtime-html';
import { resolve } from '@aurelia/kernel';
import { I18N } from '../i18n';
import { Signals, ValueConverters, valueConverterTypeName } from '../utils';

export class DateFormatValueConverter {
export class DateFormatValueConverter implements ValueConverterInstance {
public static readonly $au: ValueConverterStaticAuDefinition = {
type: valueConverterTypeName,
name: ValueConverters.dateFormatValueConverterName,
Expand Down
3 changes: 2 additions & 1 deletion packages/i18n/src/i18n.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { DI, IEventAggregator, resolve } from '@aurelia/kernel';
import { ISignaler, nowrap } from '@aurelia/runtime';
import { nowrap } from '@aurelia/runtime';
import { ISignaler } from '@aurelia/runtime-html';
import type * as i18next from 'i18next';
import { I18nInitOptions } from './i18n-configuration-options';
import { II18nextWrapper } from './i18next-wrapper';
Expand Down
4 changes: 2 additions & 2 deletions packages/i18n/src/nf/number-format-binding-behavior.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { type BindingBehaviorInstance, type Scope } from '@aurelia/runtime';
import { type Scope } from '@aurelia/runtime';
import { type BindingWithBehavior, createIntlFormatValueConverterExpression, ValueConverters, behaviorTypeName } from '../utils';
import { type BindingBehaviorStaticAuDefinition } from '@aurelia/runtime-html';
import { type BindingBehaviorStaticAuDefinition, type BindingBehaviorInstance, } from '@aurelia/runtime-html';

export class NumberFormatBindingBehavior implements BindingBehaviorInstance {
public static readonly $au: BindingBehaviorStaticAuDefinition = {
Expand Down

0 comments on commit 1c7608a

Please sign in to comment.