Skip to content

Commit

Permalink
Documenting hooks and functions
Browse files Browse the repository at this point in the history
  • Loading branch information
Andrei15193 committed Oct 16, 2024
1 parent 50dbca0 commit 78299fe
Show file tree
Hide file tree
Showing 14 changed files with 220 additions and 55 deletions.
223 changes: 193 additions & 30 deletions docs.ts

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import type { ICollectionChangedEvent } from './ICollectionChangedEvent';
import type { INotifyCollectionReordered } from './INotifyCollectionReordered';

/**
* Notifies when a collection has items added or removed to it. Item reordering is handled through the {@link INotifyCollectionReordered} interface.
* Notifies when a collection has items added or removed to it. Item reordering is handled through the {@linkcode INotifyCollectionReordered} interface.
*
* Any collection change can be reduced to [Array.splice](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Array/splice),
* event handlers receive all the relevant information to easily reproduce the operation on mapped collections.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import type { INotifyCollectionChanged } from './INotifyCollectionChanged';
import type { ICollectionReorderedEvent } from './ICollectionReorderedEvent';

/**
* Notifies when a collection has its items reordered. Adding and removing items is handled through the {@link INotifyCollectionChanged} interface.
* Notifies when a collection has its items reordered. Adding and removing items is handled through the {@linkcode INotifyCollectionChanged} interface.
* A core interface for observable collections. Components can react to this and display the new value as a consequence.
*
* Any collection change can be reduced to [Array.splice](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Array/splice),
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import type { INotifyPropertiesChanged } from '../../viewModels';
import type { INotifyCollectionChanged } from './INotifyCollectionChanged';
import type { INotifyCollectionReordered } from './INotifyCollectionReordered';
import type { ObservableCollection } from './ObservableCollection';

/**
* Represents a read-only observable collection based on the [Array](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Array) interface.
Expand Down Expand Up @@ -212,9 +213,9 @@ export interface IReadOnlyObservableCollection<TItem> extends Iterable<TItem>, A
slice(start?: number, end?: number): TItem[];

/**
* Aggregates the contained items into a {@link String} placing the provided `separator` between them.
* @param separator The separator used to insert between items when aggregating them into a {@link String}.
* @returns The aggregated items as a {@link String}.
* Aggregates the contained items into a {@linkcode String} placing the provided `separator` between them.
* @param separator The separator used to insert between items when aggregating them into a {@linkcode String}.
* @returns The aggregated items as a {@linkcode String}.
* @see [Array.join](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Array/join)
*/
join(separator?: string | null): string;
Expand Down Expand Up @@ -300,7 +301,7 @@ export interface IReadOnlyObservableCollection<TItem> extends Iterable<TItem>, A
* @param deleteCount The number of elements to remove.
* @param items The items to insert at the given start location.
* @returns A new [Array](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Array) without the removed items and containing the replacements.
* @see {@link ObservableCollection.splice}
* @see {@linkcode ObservableCollection.splice}
* @see [Array.toSpliced](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Array/toSpliced)
*/
toSpliced(start: number, deleteCount?: number, ...items: readonly TItem[]): TItem[];
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import { ReadOnlyObservableCollection } from './ReadOnlyObservableCollection';
*/
export class ObservableCollection<TItem> extends ReadOnlyObservableCollection<TItem> implements IObservableCollection<TItem> {
/**
* Initializes a new instance of the {@link ObservableCollection} class.
* Initializes a new instance of the {@linkcode ObservableCollection} class.
* @param items The items to initialize the collection with.
*/
public constructor(items?: Iterable<TItem>) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import type { ICollectionChange } from './ICollectionChange';
import type { ICollectionReorderedEvent } from './ICollectionReorderedEvent';
import type { ICollectionReorder, ICollectionItemMove } from './ICollectionReorder';
import type { IReadOnlyObservableCollection } from './IReadOnlyObservableCollection';
import type { ObservableCollection } from './ObservableCollection';
import { EventDispatcher } from '../../events';
import { ViewModel } from '../../viewModels';

Expand All @@ -19,7 +20,7 @@ export class ReadOnlyObservableCollection<TItem> extends ViewModel implements IR
private readonly _collectionReorderedEvent: EventDispatcher<this, ICollectionReorder<TItem>>;

/**
* Initializes a new instance of the {@link ReadOnlyObservableCollection} class.
* Initializes a new instance of the {@linkcode ReadOnlyObservableCollection} class.
* @param items The items to initialize the collection with.
*/
public constructor(items?: Iterable<TItem>) {
Expand Down Expand Up @@ -208,9 +209,9 @@ export class ReadOnlyObservableCollection<TItem> extends ViewModel implements IR
};

/**
* Aggregates the contained items into a {@link String} placing the provided `separator` between them.
* @param separator The separator used to insert between items when aggregating them into a {@link String}.
* @returns The aggregated items as a {@link String}.
* Aggregates the contained items into a {@linkcode String} placing the provided `separator` between them.
* @param separator The separator used to insert between items when aggregating them into a {@linkcode String}.
* @returns The aggregated items as a {@linkcode String}.
* @see [Array.join](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Array/join)
*/
public join(separator?: string | null): string {
Expand Down Expand Up @@ -670,7 +671,7 @@ export class ReadOnlyObservableCollection<TItem> extends ViewModel implements IR
* @param deleteCount The number of elements to remove.
* @param items The items to insert at the given start location.
* @returns A new [Array](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Array) without the removed items and containing the replacements.
* @see {@link ObservableCollection.splice}
* @see {@linkcode ObservableCollection.splice}
* @see [Array.toSpliced](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Array/toSpliced)
*/
public toSpliced(start: number, deleteCount?: number, ...items: readonly TItem[]): TItem[] {
Expand Down
2 changes: 1 addition & 1 deletion src/events/EventDispatcher.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import type { IEvent } from './IEvent';
import type { IEventHandler } from './IEventHandler';

/**
* A base implementation of an event. To avoid misuse, declare a private event of this type and expose it as an {@link IEvent}.
* A base implementation of an event. To avoid misuse, declare a private event of this type and expose it as an {@linkcode IEvent}.
* @template TSubject Optional, the type of object that raises the event.
* @template TEventArgs Optional, the type of the event context containing additional information about the event.
*/
Expand Down
6 changes: 3 additions & 3 deletions src/events/isEvent.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
import type { IEvent } from './IEvent';

/**
* Checkes whether the provided instance is an event (implements {@link IEvent}).
* @template TEvent The type of event to check, defaults to {@link IEvent}.
* Checkes whether the provided instance is an event (implements {@linkcode IEvent}).
* @template TEvent The type of event to check, defaults to {@linkcode IEvent}.
* @param maybeEvent The value to check if is an event.
* @returns Returns `true` if the provided instance implements {@link IEvent}; otherwise `false`.
* @returns Returns `true` if the provided instance implements {@linkcode IEvent}; otherwise `false`.
*/
export function isEvent<TEvent extends IEvent<any, any> = IEvent<any, any>>(maybeEvent: any): maybeEvent is TEvent {
return (
Expand Down
2 changes: 1 addition & 1 deletion src/forms/Form.ts
Original file line number Diff line number Diff line change
Expand Up @@ -274,7 +274,7 @@ export class Form<TValidationError = string> extends Validatable<TValidationErro
private readonly _sections: AggregateObservableCollection<Form<TValidationError>, IReadOnlyFormCollection<Form<TValidationError>, TValidationError>>;

/**
* Initializes a new instance of the {@link Form} class.
* Initializes a new instance of the {@linkcode Form} class.
*/
public constructor() {
super();
Expand Down
2 changes: 1 addition & 1 deletion src/forms/FormCollection.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import { ReadOnlyFormCollection } from './ReadOnlyFormCollection';
*/
export class FormCollection<TForm extends Form<TValidationError>, TValidationError = string> extends ReadOnlyFormCollection<TForm, TValidationError> implements IFormCollection<TForm, TValidationError> {
/**
* Initializes a new instance of the {@link FormCollection} class.
* Initializes a new instance of the {@linkcode FormCollection} class.
* @param sections The sections to initialize the collection with.
*/
public constructor(sections?: Iterable<TForm>) {
Expand Down
2 changes: 1 addition & 1 deletion src/forms/FormField.ts
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,7 @@ export class FormField<TValue, TValidationError = string> extends Validatable<TV
private _initialValue: TValue;

/**
* Initializes a new instance of the {@link FormField} class.
* Initializes a new instance of the {@linkcode FormField} class.
* @param config The initial configuration of the field (name, value, validators etc.).
*/
public constructor(config: IFormFieldConfig<TValue, TValidationError>) {
Expand Down
2 changes: 1 addition & 1 deletion src/forms/ReadOnlyFormCollection.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ export class ReadOnlyFormCollection<TForm extends Form<TValidationError>, TValid
private readonly _setupCallbacks: FormSetupCallback<TForm, TValidationError>[];

/**
* Initializes a new instance of the {@link ReadOnlyFormCollection} class.
* Initializes a new instance of the {@linkcode ReadOnlyFormCollection} class.
* @param sections The sections to initialize the collection with.
*/
public constructor(sections?: Iterable<TForm>) {
Expand Down
4 changes: 2 additions & 2 deletions src/hooks/UseViewModelMemo.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,10 @@ export type ViewModelFactory<TViewModel extends INotifyPropertiesChanged | null

/**
* Ensures a view models instance per component generated by the factory and watched for changes. Whenever the provided deps
* change a new instance is created, similar to {@link useMemo}.
* change a new instance is created, similar to {@linkcode useMemo}.
* @template TViewModel The type of view model to create.
* @param viewModelFactory The view model factory callback for creating an instance.
* @param deps Dependencies of the callback, whenever these change the callback is called again, similar to {@link useMemo}.
* @param deps Dependencies of the callback, whenever these change the callback is called again, similar to {@linkcode useMemo}.
* @returns Returns the created view model instance.
*/
export function useViewModelMemo<TViewModel extends INotifyPropertiesChanged | undefined | null>(viewModelFactory: ViewModelFactory<TViewModel>, deps: DependencyList): TViewModel {
Expand Down
6 changes: 3 additions & 3 deletions src/viewModels/isViewModel.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,10 @@ import type { INotifyPropertiesChanged } from './INotifyPropertiesChanged';
import { isEvent } from '../events';

/**
* Checkes whether the provided instance is a view model (implements {@link INotifyPropertiesChanged}).
* @template TViewModel The type of view model to check, defaults to {@link INotifyPropertiesChanged}.
* Checkes whether the provided instance is a view model (implements {@linkcode INotifyPropertiesChanged}).
* @template TViewModel The type of view model to check, defaults to {@linkcode INotifyPropertiesChanged}.
* @param maybeViewModel The value to check if is a view model.
* @returns Returns `true` if the provided instance implements {@link INotifyPropertiesChanged}; otherwise `false`.
* @returns Returns `true` if the provided instance implements {@linkcode INotifyPropertiesChanged}; otherwise `false`.
*/
export function isViewModel<TViewModel extends INotifyPropertiesChanged = INotifyPropertiesChanged>(maybeViewModel: any): maybeViewModel is TViewModel {
return (
Expand Down

0 comments on commit 78299fe

Please sign in to comment.