core-api: skip wrapping the component data store in an object

Signed-off-by: Patrik Oldsberg <poldsberg@gmail.com>
This commit is contained in:
Patrik Oldsberg
2021-03-04 11:54:14 +01:00
parent f5096bc35a
commit c5a4d041ac
2 changed files with 8 additions and 10 deletions
@@ -100,19 +100,16 @@ describe('elementData', () => {
const element = <Component />;
const container = (global as any)[
'__@backstage/component-data-store__'
].store.get(element.type);
].get(element.type);
expect(container.map.get('my-data')).toBe(data);
});
it('should should be able to attach data for newer versions', () => {
const data = { foo: 'bar' };
const Component = () => null;
(global as any)['__@backstage/component-data-store__'].store.set(
Component,
{
map: new Map([['my-data', data]]),
},
);
(global as any)['__@backstage/component-data-store__'].set(Component, {
map: new Map([['my-data', data]]),
});
const element = <Component />;
expect(getComponentData(element, 'my-data')).toBe(data);
@@ -33,9 +33,10 @@ type MaybeComponentNode = ReactNode & {
};
// The store is bridged across versions using the global object
const { store } = getGlobalSingleton('component-data-store', () => ({
store: new WeakMap<ComponentType<any>, DataContainer>(),
}));
const store = getGlobalSingleton(
'component-data-store',
() => new WeakMap<ComponentType<any>, DataContainer>(),
);
export function attachComponentData<P>(
component: ComponentType<P>,