Skip to main content

Usage

Defined in: js-api/src/u2core/usage.ts:54

What the engine does about a misuse of u2 — the one place every usage rule reports through. The mode is report unless __U2_STRICT__, localStorage['u2.strict'] or U2_STRICT says off, report or throw (1); with u2 debug on in the browser (localStorage['u2.debug'] = '1', dev) it is throw. The test runners set throw: u2's node runner, bdd and grok test. A report is a console warning; in Node a line on stderr, and U2_USAGE_REPORT=<file> appends each new one to that file as a JSON line.

Example​

DG.U2.Usage.mode = 'throw';

See​

https://public.datagrok.ai/js/samples/ui/widgets/u2-usage

Constructors​

Constructor​

new Usage(): Usage

Returns​

Usage

Accessors​

mode​

Get Signature​

get static mode(): UsageMode

Defined in: js-api/src/u2core/usage.ts:56

The mode in force: set here, else read from the environment, else report.

Returns​

UsageMode

Set Signature​

set static mode(x): void

Defined in: js-api/src/u2core/usage.ts:60

Parameters​
ParameterType
xUsageMode
Returns​

void


strict​

Get Signature​

get static strict(): boolean

Defined in: js-api/src/u2core/usage.ts:66

Strict mode: Node, a page whose __U2_STRICT__ or u2.strict is set, or u2 debug tracking on (dev, bdd). Checks that cost a walk per class run only there.

Returns​

boolean

Methods​

clear()​

static clear(): void

Defined in: js-api/src/u2core/usage.ts:97

Forgets the reports, so each misuse is logged again.

Returns​

void


fail()​

static fail(code, message): never

Defined in: js-api/src/u2core/usage.ts:86

Throws a U2UsageError whatever the mode — for a misuse u2 cannot go on from — and records it.

Parameters​

ParameterType
codestring
messagestring

Returns​

never


report()​

static report(code, message): void

Defined in: js-api/src/u2core/usage.ts:74

Reports the misuse code: in throw mode throws a U2UsageError, in report mode logs it the first time it happens at a call site, in off mode does nothing.

Parameters​

ParameterType
codestring
messagestring

Returns​

void


reports()​

static reports(): UsageReport[]

Defined in: js-api/src/u2core/usage.ts:92

Every misuse reported on this page so far, one entry per code, message and site.

Returns​

UsageReport[]