useDataSourceScope
将“DataSourceCollection”操作的副作用范围化,并在卸载时自动删除
Usage
ts
TODO;
Type Definitions
typescript
import type { DataSourceCollection } from 'cesium';
import type { MaybeRefOrGetter, ShallowReactive } from 'vue';
import type { EffcetRemovePredicate } from '../useCollectionScope';
import type { CesiumDataSource } from '../utils';
export interface UseDataSourceScopeOptions {
/**
* The collection of DataSource to be added
* @default useViewer().value.dataSources
*/
collection?: MaybeRefOrGetter<DataSourceCollection>;
/**
* The second parameter passed to the `remove` function
*
* `dataSources.remove(dataSource,destroyOnRemove)`
*/
destroyOnRemove?: boolean;
}
export interface UseDataSourceScopeRetrun {
/**
* A `Set` for storing SideEffect instance,
* which is encapsulated using `ShallowReactive` to provide Vue's reactive functionality
*/
scope: Readonly<ShallowReactive<Set<CesiumDataSource>>>;
/**
* Add SideEffect instance
*/
add: <T extends CesiumDataSource>(dataSource: T) => Promise<T>;
/**
* Remove specified SideEffect instance
*/
remove: (dataSource: CesiumDataSource, destroy?: boolean) => boolean;
/**
* Remove all SideEffect instance that meets the specified criteria
*/
removeWhere: (predicate: EffcetRemovePredicate<CesiumDataSource>, destroy?: boolean) => void;
/**
* Remove all SideEffect instance within current scope
*/
removeScope: (destroy?: boolean) => void;
}
/**
* // Scope the SideEffects of `DataSourceCollection` operations and automatically remove them when unmounted
*/
export declare function useDataSourceScope(options?: UseDataSourceScopeOptions): UseDataSourceScopeRetrun;