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 = {
}
return extensionsStore.get(extensionName);
},
hasFullApiRegistered: (targetMethods, newMethods) => {
return newMethods.find((fn) => !targetMethods.includes(fn)) === undefined;
},
};
/** Class representing a Source Editor Instance */
......@@ -132,7 +136,9 @@ export default class EditorInstance {
const existingExt = utils.getStoredExtension(extensionsStore, definition.extensionName);
if (existingExt) {
if (isEqual(extension.setupOptions, existingExt.setupOptions)) {
return existingExt;
if (utils.hasFullApiRegistered(this.extensionsAPI, Object.keys(existingExt.api))) {
return existingExt;
}
}
this.unuseExtension(extensionsStore, existingExt);
}
......
......@@ -277,6 +277,17 @@ describe('Source Editor Instance', () => {
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`
desc | currentSetupOptions | newSetupOptions | expectedCallTimes
${'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