Skip to content

Allow instantiation of multiple notebooks inside a single scope #40

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 1 commit into from

Conversation

GordonSmith
Copy link
Contributor

FWIW I am creating notebooks at runtime (rather than build time) and having a single runtime/main is problematic.

Copy link
Member

@mbostock mbostock left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Makes sense; we should generalize this to be more object-oriented. I think the pattern should probably be to instantiate something, an object that owns the runtime and the main module, and then call define on the instantiated object as a method, rather than passing the main module through to define.

@GordonSmith
Copy link
Contributor Author

That would be even better, was going with a minimal PR.

@GordonSmith GordonSmith force-pushed the GLOBAL_MAIN branch 2 times, most recently from 5004fe2 to 0e51b2c Compare August 9, 2025 17:31
@GordonSmith GordonSmith requested a review from mbostock August 9, 2025 17:32
@GordonSmith
Copy link
Contributor Author

Updated as suggested (included the ability re-define or undefine a cell, as per our previous discussion)

Copy link
Member

@mbostock mbostock left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for incorporating my feedback. This looks useful.

For backwards compatibility, I think we’ll want a defaultInstance and retain the existing define, main, runtime symbols (on top of the defaultInstance, which doesn’t need to be exposed directly). We can deprecate these but I’d like to maintain compatibility with the current release.

Copy link
Member

@mbostock mbostock left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I’d also prefer to keep the redefining and stateById logic out of this PR and leave that in userland for now. You should still be able to implement it as described in #26 (comment).

Comment on lines 42 to 48
this.main.constructor.prototype.defines = function (this: Module, name: string): boolean {
return (
this._scope.has(name) ||
this._builtins.has(name) ||
this._runtime._builtin._scope.has(name)
);
};
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

With the defaultInstance approach, this mutation could be done statically. (But really we should move it to the Runtime itself… Future work!)

@mbostock
Copy link
Member

Superseded by #49.

@mbostock mbostock closed this Aug 11, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants