Theia Workshop - Monaco Editor Model Updating Questions

In the workshop exercise 3, there are two main functions in (https://github.com/TypeFox/theia-workshop/blob/solution-3/jsonschema-form-extension/src/browser/jsonschema-form-view.tsx) that perform updates. I think the “submit” function is responsible for updating the text in the editor, while “reconcileFormData” is responsible for updating the form. What do “schemaStorage.update(formData)” and “uiSchemaStorage.update(formData)” actually do? Isn’t the model updated on the change event in “submit”?

If I wanted to update another react widget based on edits on this form, what would the general workflow be? do I just need to create another reference to the model?

Also, what is a DisposableCollection for?

[original thread by shortwavedave]

When you dispose a compoenent in order it to be garbage collected all listeners to it should be disposed as well. One does it by disposing event emitters. The issue is that if during disposing something throws other things won’t be disposed, so you have do try - catch all the time.

Instead you can create DisposableCollection and dispose it at proper momement. It will make sure that all collected disopsable are disposed without affecting each other.

You can also use it on client side to dispose listeners of something, for example you want to listen to an active editor, but it gets changed over the time. So you have a disposable collection which should be disposed when an active editor changed and then you add new listeners to it.

You can also compose disposable collections, i.e. if you listen to an acitve editor in some widget, then you can push a disposable collection with active editor listeners to a disposable collection of this widget, and when a widget is disposed listeners to an acitve editor will be disposed as well.

It was about DisposableCollection, now about example :slight_smile:

the json file contains references to schemas which define its format and UI format

so when these references are changed in the file then schema and uiSchema should be updated to point to new schemas

it’s what schemaStorage.update and uiSchemaStorage.update do, they resolve a URI to new schema and if it is different from the current they switch to a new schema model

If I wanted to update another react widget based on edits on this form, what would the general workflow be? do I just need to create another reference to the model?

yes, you can create a new reference, there can be only one model for each uri and different clients can use it as a single source of truth

[shortwavedave]

so good, thank you. Maybe I can collect your responses and make a pull request with comments on the classes I’ve asked about

We need a proper docs here as well: https://www.theia-ide.org/doc/index.html

I like how in IntelliJ docs are structured a problem + code snippet + small explanation, like here: http://www.jetbrains.org/intellij/sdk/docs/tutorials/custom_language_support/reference_contributor.html

then all problems are structured in table of content

We could have such kind of the tutorial for widgets.