Commit 6c29b2da authored by Denys Mishunov's avatar Denys Mishunov Committed by Himanshu Kapoor

Fix re-use of extensions between instances

Changelog: fixed
parent 69a452c8
...@@ -50,6 +50,10 @@ const utils = { ...@@ -50,6 +50,10 @@ const utils = {
} }
return extensionsStore.get(extensionName); return extensionsStore.get(extensionName);
}, },
hasFullApiRegistered: (targetMethods, newMethods) => {
return newMethods.find((fn) => !targetMethods.includes(fn)) === undefined;
},
}; };
/** Class representing a Source Editor Instance */ /** Class representing a Source Editor Instance */
...@@ -132,8 +136,10 @@ export default class EditorInstance { ...@@ -132,8 +136,10 @@ export default class EditorInstance {
const existingExt = utils.getStoredExtension(extensionsStore, definition.extensionName); const existingExt = utils.getStoredExtension(extensionsStore, definition.extensionName);
if (existingExt) { if (existingExt) {
if (isEqual(extension.setupOptions, existingExt.setupOptions)) { if (isEqual(extension.setupOptions, existingExt.setupOptions)) {
if (utils.hasFullApiRegistered(this.extensionsAPI, Object.keys(existingExt.api))) {
return existingExt; return existingExt;
} }
}
this.unuseExtension(extensionsStore, existingExt); this.unuseExtension(extensionsStore, existingExt);
} }
......
...@@ -277,6 +277,17 @@ describe('Source Editor Instance', () => { ...@@ -277,6 +277,17 @@ describe('Source Editor Instance', () => {
expect(extensionStore.set).toHaveBeenCalledWith('SEClassExtension', extension1); expect(extensionStore.set).toHaveBeenCalledWith('SEClassExtension', extension1);
}); });
it('correctly registers methods from the existing extension on an instance', () => {
const seInstance2 = new SourceEditorInstance({}, extensionStore);
seInstance.use({ definition: SEClassExtension });
const val1 = seInstance.classExtMethod();
seInstance2.use({ definition: SEClassExtension });
expect(seInstance2.classExtMethod).toBeDefined();
expect(seInstance2.classExtMethod()).toBe(val1); // from helpers.js we know classExtMethod()returns a string. Hence `toBe`
});
it.each` it.each`
desc | currentSetupOptions | newSetupOptions | expectedCallTimes desc | currentSetupOptions | newSetupOptions | expectedCallTimes
${'updates'} | ${undefined} | ${defSetupOptions} | ${2} ${'updates'} | ${undefined} | ${defSetupOptions} | ${2}
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment