ProgressHandler

Introduction

vtkProgressHandler stores dataset topologies as an explicit connectivity table
listing the point ids that make up each cell.

See Also

vtkDataArray

Methods

extend

Method used to decorate a given object (publicAPI+model) with vtkProgressHandler characteristics.

Argument Type Required Description
publicAPI Yes object on which methods will be bounds (public)
model Yes object on which data structure will be bounds (protected)
initialValues IProgressHandlerInitialValues No (default: {})

getWorkCount

isWorking

newInstance

Method used to create a new instance of vtkProgressHandler

Argument Type Required Description
initialValues IProgressHandlerInitialValues No for pre-setting some of its content

startWork

stopWork

wrapPromise

Argument Type Required Description
promise Yes

wrapPromiseFunction

Argument Type Required Description
fn Yes

Source

index.d.ts
import { vtkObject } from "../../../interfaces" ;

/**
*
*/
export interface IProgressHandlerInitialValues {
workCount?: number;
}

export interface vtkProgressHandler extends vtkObject {

/**
*
*/
getWorkCount(): number;

/**
*
*/
startWork(): void;

/**
*
*/
stopWork(): void;

/**
*
*/
isWorking(): boolean;

/**
*
* @param promise
*/
wrapPromise(promise : any): Promise<any>;

/**
*
* @param fn
*/
wrapPromiseFunction(fn : any): any;
}

/**
* Method used to decorate a given object (publicAPI+model) with vtkProgressHandler characteristics.
*
* @param publicAPI object on which methods will be bounds (public)
* @param model object on which data structure will be bounds (protected)
* @param {IProgressHandlerInitialValues} [initialValues] (default: {})
*/
export function extend(publicAPI: object, model: object, initialValues?: IProgressHandlerInitialValues): void;

/**
* Method used to create a new instance of vtkProgressHandler
* @param {IProgressHandlerInitialValues} [initialValues] for pre-setting some of its content
*/
export function newInstance(initialValues?: IProgressHandlerInitialValues): vtkProgressHandler;

/**
* vtkProgressHandler stores dataset topologies as an explicit connectivity table
* listing the point ids that make up each cell.
*
* @see vtkDataArray
*/
export declare const vtkProgressHandler: {
newInstance: typeof newInstance;
extend: typeof extend;
}
export default vtkProgressHandler;
index.js
import macro from 'vtk.js/Sources/macros';

// ----------------------------------------------------------------------------
// vtkProgressHandler methods
// ----------------------------------------------------------------------------

function vtkProgressHandler(publicAPI, model) {
// Set our className
model.classHierarchy.push('vtkProgressHandler');

publicAPI.startWork = () => {
model.workCount += 1;
if (model.workCount === 1) {
publicAPI.invokeChange(true);
}
};

publicAPI.stopWork = () => {
model.workCount -= 1;
if (model.workCount === 0) {
publicAPI.invokeChange(false);
}
};

publicAPI.isWorking = () => !!model.workCount;

publicAPI.wrapPromise = (promise) => {
publicAPI.startWork();
return new Promise((resolve, reject) => {
promise.then(
(...resolveArgs) => {
publicAPI.stopWork();
resolve(...resolveArgs);
},
(rejectError) => {
publicAPI.stopWork();
reject(rejectError);
}
);
});
};

publicAPI.wrapPromiseFunction =
(fn) =>
(...args) =>
publicAPI.wrapPromise(fn(...args));
}

// ----------------------------------------------------------------------------
// Object factory
// ----------------------------------------------------------------------------

const DEFAULT_VALUES = {
workCount: 0,
};

// ----------------------------------------------------------------------------

export function extend(publicAPI, model, initialValues = {}) {
Object.assign(model, DEFAULT_VALUES, initialValues);

// Object methods
macro.obj(publicAPI, model);
macro.event(publicAPI, model, 'change');
macro.get(publicAPI, model, ['workCount']);

// Object specific methods
vtkProgressHandler(publicAPI, model);
}

// ----------------------------------------------------------------------------

export const newInstance = macro.newInstance(extend, 'vtkProgressHandler');

// ----------------------------------------------------------------------------

export default { newInstance, extend };