@arcgis/map-components
Version:
ArcGIS Map Components
84 lines (83 loc) • 3.66 kB
TypeScript
/// <reference types="@arcgis/core/interfaces.d.ts" />
import { BaseComponent, EventEmitter } from '@arcgis/components-controllers';
import { AccessorController } from '@arcgis/components-controllers/accessor';
import { Nil } from '@arcgis/components-utils';
import { default as ArcgisMap } from '@arcgis/core/Map';
import { ArcgisReferenceElement } from '../utils/component-utils';
type Requires<Props, ViewModel extends ViewModelInstance> = BaseComponent & Pick<ViewModel, keyof Props & keyof ViewModel> & Uses<ViewModel>;
type ViewModelInstance = __esri.Accessor & Partial<__esri.Evented> & {
state?: string;
view?: __esri.LinkChartView | __esri.MapView | __esri.SceneView | nullish;
map?: ArcgisMap | Nil;
};
type Uses<ViewModel extends ViewModelInstance> = {
reactiveUtils?: typeof __esri.reactiveUtils;
state?: ViewModel["state"];
icon: Nil | string;
label: Nil | string;
referenceElement: ArcgisReferenceElement | Nil | string;
arcgisReady: EventEmitter;
position: __esri.UIPosition;
arcgisPropertyChange: EventEmitter<{
name: string;
}> | undefined;
el: HTMLElement & {
childElem?: HTMLElement & {
ownedBy?: HTMLElement;
};
view?: __esri.MapView | __esri.SceneView | undefined;
};
autoDestroyDisabled: boolean;
destroy: () => Promise<void>;
};
/**
* A controller for a mapping component that:
* - loads the viewModel
* - initializes the viewModel with the component's properties
* - does two-way binding between view model and component properties
* - re-emits the viewModel's events on the component
* - type-checks everything ✨
*
* Documentation:
* https://qawebgis.esri.com/components/lumina/transition-from-widgets#useviewmodel-controller
*
* TEST: add test cases for this controller
*/
export declare const makeViewModelController: <Props, ViewModel extends ViewModelInstance, OmitProps extends string = never>(loadViewModel: ((props: Omit<Props, "view">) => Promise<ViewModel>) | (new (props: Omit<Props, "view">) => ViewModel), _options?: {
/**
* Don't expose the following ViewModels's properties on the component.
* You can also bind the property to \@State rather than \@Prop if you
* wish to use it internally only:
*
* @example
* \@State() timeZone = this.viewModel.timeZone;
*/
omitProps: OmitProps[];
}) => (component: Requires<Omit<Props, OmitProps>, ViewModel>, options?: {
editConstructorProperties(props: Props): Promise<Props> | Props;
}) => ViewModel;
export declare class ViewModelController<Props, ViewModel extends ViewModelInstance> extends AccessorController<Props, ViewModel, Uses<ViewModel>> {
hostConnected(): void;
hostLoad(): Promise<void>;
hostLoaded(): void;
hostDisconnected(): void;
hostDestroy(): void;
private _watchMetaProperties;
/**
* Destroy the component if view gets destroyed.
*
* When view is destroyed, component disconnect is triggered, which will
* destroy the component in 1s but that can be too late, because in the
* meanwhile, a watcher on the widget/viewModel instance may get triggered,
* and throw an error if it's not able to access this.view.map or etc
* (happens in VersionManagementViewModel for example).
*
* We can't check for this in disconnectedCallback though as, if the entire
* component tree is removed, the disconnect for the component will be
* triggered before that of arcgis-map, so the view might not be destroyed
* yet at that point.
*/
private _watchViewDestroy;
private _watchViewDestroyHandle?;
}
export {};