mirror of
https://github.com/nasa/openmct.git
synced 2025-06-22 17:08:57 +00:00
Support for remote mutation of Notebooks with Couch DB (#3887)
* Update notebook automatically when modified by another user * Don't persist selected and default page and section IDs on notebook object * Fixing object synchronization bugs * Adding unit tests * Synchronize notebooks AND plans * Removed observeEnabled flag Co-authored-by: Shefali Joshi <simplyrender@gmail.com>
This commit is contained in:
@ -45,6 +45,8 @@ function ObjectAPI(typeRegistry, openmct) {
|
||||
this.rootProvider = new RootObjectProvider(this.rootRegistry);
|
||||
this.cache = {};
|
||||
this.interceptorRegistry = new InterceptorRegistry();
|
||||
|
||||
this.SYNCHRONIZED_OBJECT_TYPES = ['notebook', 'plan'];
|
||||
}
|
||||
|
||||
/**
|
||||
@ -404,11 +406,16 @@ ObjectAPI.prototype._toMutable = function (object) {
|
||||
let provider = this.getProvider(identifier);
|
||||
|
||||
if (provider !== undefined
|
||||
&& provider.observe !== undefined) {
|
||||
&& provider.observe !== undefined
|
||||
&& this.SYNCHRONIZED_OBJECT_TYPES.includes(object.type)) {
|
||||
let unobserve = provider.observe(identifier, (updatedModel) => {
|
||||
mutableObject.$refresh(updatedModel);
|
||||
if (updatedModel.persisted > mutableObject.modified) {
|
||||
//Don't replace with a stale model. This can happen on slow connections when multiple mutations happen
|
||||
//in rapid succession and intermediate persistence states are returned by the observe function.
|
||||
mutableObject.$refresh(updatedModel);
|
||||
}
|
||||
});
|
||||
mutableObject.$on('$destroy', () => {
|
||||
mutableObject.$on('$_destroy', () => {
|
||||
unobserve();
|
||||
});
|
||||
}
|
||||
|
@ -163,14 +163,22 @@ describe("The Object API", () => {
|
||||
key: 'test-key'
|
||||
},
|
||||
name: 'test object',
|
||||
type: 'notebook',
|
||||
otherAttribute: 'other-attribute-value',
|
||||
modified: 0,
|
||||
persisted: 0,
|
||||
objectAttribute: {
|
||||
embeddedObject: {
|
||||
embeddedKey: 'embedded-value'
|
||||
}
|
||||
}
|
||||
};
|
||||
updatedTestObject = Object.assign({otherAttribute: 'changed-attribute-value'}, testObject);
|
||||
updatedTestObject = Object.assign({
|
||||
otherAttribute: 'changed-attribute-value'
|
||||
}, testObject);
|
||||
updatedTestObject.modified = 1;
|
||||
updatedTestObject.persisted = 1;
|
||||
|
||||
mockProvider = jasmine.createSpyObj("mock provider", [
|
||||
"get",
|
||||
"create",
|
||||
@ -182,6 +190,8 @@ describe("The Object API", () => {
|
||||
mockProvider.observeObjectChanges.and.callFake(() => {
|
||||
callbacks[0](updatedTestObject);
|
||||
callbacks.splice(0, 1);
|
||||
|
||||
return () => {};
|
||||
});
|
||||
mockProvider.observe.and.callFake((id, callback) => {
|
||||
if (callbacks.length === 0) {
|
||||
@ -189,6 +199,8 @@ describe("The Object API", () => {
|
||||
} else {
|
||||
callbacks[0] = callback;
|
||||
}
|
||||
|
||||
return () => {};
|
||||
});
|
||||
|
||||
objectAPI.addProvider(TEST_NAMESPACE, mockProvider);
|
||||
|
Reference in New Issue
Block a user