Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 5 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -210,7 +210,11 @@ module1.variable().import("foo", "bar", module0);

#### *variable*.delete()

[Source](https://github.com/observablehq/runtime/blob/main/src/variable.js) · Deletes this variable’s current definition and name, if any. Any variable in this module that references this variable as an input will subsequently throw a ReferenceError. If exactly one other variable defined this variable’s previous name, such that that variable throws a ReferenceError due to its duplicate definition, that variable’s original definition is restored.
[Source](https://github.com/observablehq/runtime/blob/main/src/variable.js) · Deletes this variable’s current definition and name, if any. Any variable that references this variable as an input will subsequently throw a ReferenceError, unless the variable is subsequently redefined. If exactly one other variable defined this variable’s previous name, such that that variable throws a ReferenceError due to its duplicate definition, that variable’s original definition is restored.

#### *variable*.dispose()

[Source](https://github.com/observablehq/runtime/blob/main/src/variable.js) · Invalidates this variable’s current value and prevents future computation and observation. The variable should no longer be used after being disposed. You may also want to delete the variable to invalidate references to the now-disposed variable.

### Observers

Expand Down
5 changes: 1 addition & 4 deletions src/runtime.js
Original file line number Diff line number Diff line change
Expand Up @@ -39,10 +39,7 @@ Object.defineProperties(Runtime.prototype, {
function runtime_dispose() {
this._computing = Promise.resolve();
this._disposed = true;
this._variables.forEach(v => {
v._invalidate();
v._version = NaN;
});
this._variables.forEach(v => v.dispose());
}

function runtime_module(define, observer = noop) {
Expand Down
6 changes: 6 additions & 0 deletions src/variable.js
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ Object.defineProperties(Variable.prototype, {
_resolve: {value: variable_resolve, writable: true, configurable: true},
define: {value: variable_define, writable: true, configurable: true},
delete: {value: variable_delete, writable: true, configurable: true},
dispose: {value: variable_dispose, writable: true, configurable: true},
import: {value: variable_import, writable: true, configurable: true}
});

Expand Down Expand Up @@ -202,6 +203,11 @@ function variable_import(remote, name, module) {
return variable_defineImpl.call(this, String(name), [module._resolve(String(remote))], identity);
}

function variable_dispose() {
this._invalidate();
this._version = NaN;
}

function variable_delete() {
return variable_defineImpl.call(this, null, [], noop);
}
Expand Down
Loading