Skip to main content

Editor.ScopedConnection

Class

Stores event listener connections, automatically cleaned up on scope exit.

Index

Example

// ScopedConnection is the handle returned by signal.connect(). Store it
// for the lifetime you want the handler to stay active — disconnect() in
// stop() to cleanly detach when the plugin unloads.
const model = this.pluginSystem.findInterface(Editor.Model.IModel) as Editor.Model.IModel;

// onProjectChanged fires when switching projects; onProjectSaving fires
// after a save completes (use it to react to Save As landing on disk).
const changedConn: Editor.ScopedConnection = model.onProjectChanged.connect(() => {
console.log('switched to a new project');
});
const savingConn: Editor.ScopedConnection = model.onProjectSaving.connect(
(mode: Editor.Model.ProjectSaveMode) => {
console.log(`project saved, mode=${mode}`);
}
);

// Retain both connections so they are not garbage-collected while alive.
this.connections.push(changedConn, savingConn);
console.log(`Active connections: ${this.connections.filter(c => c.isConnected).length}`);

Extends

Properties

isConnected

readonly isConnected: boolean

Indicates whether the connection is currently active.

Methods

disconnect()

disconnect(): boolean

Disconnects the associated signal connection and returns true if it was active.

Returns

boolean


dispose()

dispose(): void

Free the guarded resource immediately.

Returns

void

Inherited from

IGuard.dispose


getTypeName()

static getTypeName(): string

Returns the type name of this class.

Returns

string

Overrides

IGuard.getTypeName


getTypeName()

getTypeName(): string

Returns the name of this object's type.

Returns

string

Inherited from

IGuard.getTypeName


isOfType()

isOfType(type): boolean

Returns true if the object is of the specified type.

Parameters

ParameterType
typestring

Returns

boolean

Inherited from

IGuard.isOfType


isSame()

isSame(other): boolean

Returns true if this object refers to the same instance as the given object.

Parameters

ParameterType
otherScriptObject

Returns

boolean

Inherited from

IGuard.isSame