Skip to content
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

Only serialize models not already known to a document #202

Merged
merged 1 commit into from
Apr 17, 2024
Merged
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
8 changes: 7 additions & 1 deletion src/widgets.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@
type DocumentChangedEvent = any
type Receiver = any
type Fragment = any
type HasProps = any
type Ref = any

const { keys, values } = Object

Expand All @@ -27,12 +29,12 @@
div: string
}

export interface DocumentChanged {

Check warning on line 32 in src/widgets.ts

View workflow job for this annotation

GitHub Actions / build

Interface name `DocumentChanged` must match the RegExp: /^I[A-Z]/u
event: 'jsevent'
kind: string
}

export interface ModelChanged extends DocumentChanged {

Check warning on line 37 in src/widgets.ts

View workflow job for this annotation

GitHub Actions / build

Interface name `ModelChanged` must match the RegExp: /^I[A-Z]/u
event: 'jsevent'
kind: 'ModelChanged'
id: string
Expand All @@ -40,7 +42,7 @@
attr: string
}

export interface MessageSent extends DocumentChanged {

Check warning on line 45 in src/widgets.ts

View workflow job for this annotation

GitHub Actions / build

Interface name `MessageSent` must match the RegExp: /^I[A-Z]/u
event: 'jsevent'
kind: 'MessageSent'
msg_data: {
Expand Down Expand Up @@ -95,7 +97,7 @@
this._receiver = new Receiver()
this.model.on('change:render_bundle', () => this.render())
if (
(window as any).Jupyter != null &&

Check warning on line 100 in src/widgets.ts

View workflow job for this annotation

GitHub Actions / build

Expected '!==' and instead saw '!='
(window as any).Jupyter.notebook != null
) {
// Handle classic Jupyter notebook
Expand Down Expand Up @@ -199,7 +201,11 @@
return
}
const { Serializer } = bk_require('core/serialization')
const serializer = new Serializer()
const references: Map<HasProps, Ref> = new Map()
for (const model of event.document._all_models.values()) {
references.set(model, model.ref())
}
const serializer = new Serializer({references})
const event_rep = serializer.encode(event)
event_rep.event = 'jsevent'
this._send(event_rep)
Expand Down
Loading