Skip to content

Commit 9b27700

Browse files
committed
Fix circular imports.
1 parent 05cccbc commit 9b27700

File tree

2 files changed

+18
-4
lines changed

2 files changed

+18
-4
lines changed

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -96,7 +96,7 @@ Builtins must have constant values; unlike [variables](#variables), they cannot
9696

9797
Returns a new [module](#modules) for this [runtime](#runtimes).
9898

99-
If *define* is specified, it is a function which defines the new module’s [variables](#variables). If this runtime already has a module for the specified *define* function, the existing module is returned; otherwise, a new module is created, and the *define* function is called, being passed this runtime and the specified *observer* factory function. If *define* is not specified, a new module is created and returned.
99+
If *define* is specified, it is a function which defines the new module’s [variables](#variables) by calling *runtime*.module (with no arguments) and then calling [*module*.variable](#module_variable) on the returned module as desired. If this runtime already has a module for the specified *define* function, the existing module is returned; otherwise, a new module is created, and the *define* function is called, being passed this runtime and the specified *observer* factory function. If *define* is not specified, a new module is created and returned.
100100

101101
If an *observer* factory function is specified, it is called for each named variable in the returned module, being passed the variable’s name. The [standard inspector](#inspector) is available as a ready-made observer: it displays DOM elements “as-is” and renders interactive displays for other arbitrary values such as numbers and objects.
102102

src/runtime.js

Lines changed: 17 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ export default function Runtime(builtins = new Library, global = window_global)
1717
_dirty: {value: new Set},
1818
_updates: {value: new Set},
1919
_computing: {value: null, writable: true},
20+
_init: {value: null, writable: true},
2021
_modules: {value: new Map},
2122
_variables: {value: new Set},
2223
_disposed: {value: false, writable: true},
@@ -50,10 +51,23 @@ function runtime_dispose() {
5051
}
5152

5253
function runtime_module(define, observer = noop) {
53-
if (define === undefined) return new Module(this);
54-
let module = this._modules.get(define);
54+
let module;
55+
if (define === undefined) {
56+
if (module = this._init) {
57+
this._init = null;
58+
return module;
59+
}
60+
return new Module(this);
61+
}
62+
module = this._modules.get(define);
5563
if (module) return module;
56-
this._modules.set(define, module = define(this, observer));
64+
this._init = module = new Module(this);
65+
this._modules.set(define, module);
66+
try {
67+
define(this, observer);
68+
} finally {
69+
this._init = null;
70+
}
5771
return module;
5872
}
5973

0 commit comments

Comments
 (0)