-
Notifications
You must be signed in to change notification settings - Fork 1.3k
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
[API] Changes to mutation API #3483
Conversation
@@ -26,7 +26,7 @@ | |||
class="js-lad-table__body__row" | |||
@contextmenu.prevent="showContextMenu" | |||
> | |||
<td class="js-first-data">{{ name }}</td> | |||
<td class="js-first-data">{{ domainObject.name }}</td> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
domainObject
provided by view API is now automatically kept in sync, so I can just use Vue reactivity to update the name when it changes. No need for any event listeners at all.
… an error otherwise
Well, that was a Homeric epic. I believe I have addressed all of the review comments, merged from master, and fixed the infinity bugs that came out of it. |
Oops, missed one feedback comment. Fixed now. |
@akhenry |
@shefalijoshi The Open MCT View API. View providers are now supplied with a MutableDomainObject to their |
@akhenry please resolve conflict so we can merge this. |
@shefalijoshi Done! |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM
Reviewer Checklist
Changes appear to address issue? | Y |
Appropriate unit tests included? | Y |
Code style and in-line documentation are appropriate? | Y |
Commit messages meet standards? | Y |
Has associated issue been labelled unverified ? |
Y |
@akhenry , merged, but can you provide an issue with testing instructions? |
Changes how object mutation works behind the scenes in order to keep objects in sync automatically when their model changes.
openmct.objects.mutate
andopenmct.objects.observe
should still be used in the same way that they were before.MutableDomainObject
that exposes mutator and observer functions that allow objects to be mutated in such a way that all instances can be kept in sync.MutableDomainObject
s from the API, instead of regular domain objects. These are automatically updated when mutation occurs on any instance of the object, replacing the need for "*
" listeners. Note that the view API now provides objects in this form by default. Therefore, you do not need to do anything differently in views, the domain objects will just magically keep themselves up to date.openmct.objects.get
(you should ask why you need to do this) and you want it to magically keep itself in sync, there is a new API function namedopenmct.objects.getMutable(identifier)
. Note that if you do this you will be responsible for the object's lifecycle. It relies on listeners which must be destroyed when the object is no longer needed, otherwise memory leaks will occur. You can destroy aMutableDomainObject
and its (internal) listeners by callingopenmct.objects.destroyMutable(mutableDomainObject)
. Any listeners created by calls toopenmct.objects.observe
need to be cleaned up separately.MutableDomainObject
is retrieved using the Composition API, all children will be returned asMutableDomainObjects
automatically. Their lifecycle will be managed automatically, and is tied to the lifecycle of the parent.MutableDomainObject
provided by the Open MCT framework itself (eg. provided to view providers by the View API, or from the composition API) will have its lifecycle managed by Open MCT, you don't need to worry destroying it.*
" observers have been now been replaced. Due to time constraints I was unable to replace all of them, so I will file followup issues to address them.observedDomainObject
,internalDomainObject
, etc.). I have removed these wherever I have changed view code, but there are still a lot of examples of this in our codebase. We should avoid having multiple different instances of the same domain object in the same view, it's very confusing to developers. This was I think partly necessitated by the need to use "*
" observers, so hopefully we won't need to do it going forward.TL;DR
*
" observers are no longer needed anywhere. In views, the domain object provided to the view provider will automatically be kept in sync, so if the domain object is a reactive Vue property (eg. it's passed in viaprops
) then Vue reactivity will take care of updating the view automatically.openmct.objects.getMutable(identifier)
. However, you will be responsible for destroying it.Note: I updated the Object API to be an ES6 module. This was necessitated by a weird issue in Webpack with using a mixture of require and ES6 imports that I could not resolve using the usual
.default
fix. This resulted the indentation of the whole file shifting, which means every line shows up as changed in the diff unless you use theHide whitespace changes
option in the File Changes tab.To do:
*
" listeners Replace remaining "*
" observers #3553