Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

docs: add alpha tags to unfinished binding APIs #5665

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{
"type": "none",
"comment": "docs: add alpha tags to unfinished binding APIs",
"packageName": "@microsoft/fast-element",
"email": "[email protected]",
"dependentChangeType": "none"
}
16 changes: 8 additions & 8 deletions packages/web-components/fast-element/docs/api-report.md
Original file line number Diff line number Diff line change
Expand Up @@ -60,26 +60,26 @@ export interface Behavior<TSource = any, TParent = any, TGrandparent = any> {
unbind(source: TSource, context: ExecutionContext<TParent, TGrandparent>): void;
}

// @public (undocumented)
// @alpha (undocumented)
export function bind<T = any>(binding: Binding<T>, config?: BindingConfig<T> | DefaultBindingOptions): CaptureType<T>;

// @public
export type Binding<TSource = any, TReturn = any, TParent = any> = (source: TSource, context: ExecutionContext<TParent>) => TReturn;

// @public (undocumented)
// @alpha (undocumented)
export type BindingBehaviorFactory = {
createBehavior(targets: ViewBehaviorTargets): ViewBehavior;
};

// @public (undocumented)
// @alpha (undocumented)
export interface BindingConfig<T = any> {
// (undocumented)
mode: BindingMode;
// (undocumented)
options: any;
}

// @public (undocumented)
// @alpha (undocumented)
export interface BindingMode {
// (undocumented)
attribute: BindingType;
Expand All @@ -104,7 +104,7 @@ export interface BindingObserver<TSource = any, TReturn = any, TParent = any> ex

// Warning: (ae-forgotten-export) The symbol "HTMLBindingDirective" needs to be exported by the entry point index.d.ts
//
// @public (undocumented)
// @alpha (undocumented)
export type BindingType = (directive: HTMLBindingDirective) => BindingBehaviorFactory;

// @public
Expand Down Expand Up @@ -196,7 +196,7 @@ export function customElement(nameOrDef: string | PartialFASTElementDefinition):
// @public
export type DecoratorAttributeConfiguration = Omit<AttributeConfiguration, "property">;

// @public (undocumented)
// @alpha (undocumented)
export type DefaultBindingOptions = {
capture?: boolean;
};
Expand Down Expand Up @@ -415,10 +415,10 @@ export interface ObservationRecord {

// Warning: (ae-forgotten-export) The symbol "BindingConfigResolver" needs to be exported by the entry point index.d.ts
//
// @public (undocumented)
// @alpha (undocumented)
export const onChange: BindingConfig<DefaultBindingOptions> & BindingConfigResolver<DefaultBindingOptions>;

// @public (undocumented)
// @alpha (undocumented)
export const oneTime: BindingConfig<DefaultBindingOptions> & BindingConfigResolver<DefaultBindingOptions>;

// @public
Expand Down
37 changes: 36 additions & 1 deletion packages/web-components/fast-element/src/templating/binding.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,15 +15,30 @@ import {
import type { CaptureType } from "./template.js";
import type { SyntheticView } from "./view.js";

// TODO: Fix the code docs in this file.

/**
* @alpha
*/
export type BindingBehaviorFactory = {
createBehavior(targets: ViewBehaviorTargets): ViewBehavior;
};

/**
* @alpha
*/
export type BindingType = (directive: HTMLBindingDirective) => BindingBehaviorFactory;

/**
* @alpha
*/
export const notSupportedBindingType: BindingType = () => {
throw new Error();
};

/**
* @alpha
*/
export interface BindingMode {
attribute: BindingType;
booleanAttribute: BindingType;
Expand All @@ -33,7 +48,9 @@ export interface BindingMode {
event: BindingType;
}

/* eslint-disable-next-line @typescript-eslint/no-unused-vars */
/**
* @alpha
*/
export interface BindingConfig<T = any> {
mode: BindingMode;
options: any;
Expand Down Expand Up @@ -268,6 +285,9 @@ class OneTimeBinding extends TargetUpdateBinding {

const signals: Record<string, undefined | Function | Function[]> = Object.create(null);

/**
* @alpha
*/
export function sendSignal(signal: string): void {
const found = signals[signal];
if (found) {
Expand Down Expand Up @@ -446,6 +466,9 @@ class OneTimeEventListener extends EventListener {
}
}

/**
* @alpha
*/
export type DefaultBindingOptions = {
capture?: boolean;
};
Expand All @@ -454,18 +477,27 @@ const defaultBindingOptions: DefaultBindingOptions = {
capture: false,
};

/**
* @alpha
*/
export const onChange = OnChangeBinding.createBindingConfig(
defaultBindingOptions,
directive => new EventListener(directive)
);

/**
* @alpha
*/
export const oneTime = OneTimeBinding.createBindingConfig(
defaultBindingOptions,
directive => new OneTimeEventListener(directive)
);

const signalMode: BindingMode = OnSignalBinding.createBindingMode();

/**
* @alpha
*/
export const signal = <T = any>(options: string | Binding<T>): BindingConfig<T> => {
return { mode: signalMode, options };
};
Expand Down Expand Up @@ -537,6 +569,9 @@ export class HTMLBindingDirective extends InlinableHTMLDirective {
}
}

/**
* @alpha
*/
export function bind<T = any>(
binding: Binding<T>,
config: BindingConfig<T> | DefaultBindingOptions = onChange
Expand Down