Skip to content

Commit

Permalink
Merge pull request #4802 from backstage/rugvip/onestore
Browse files Browse the repository at this point in the history
core-api: skip wrapping the component data store in an object
  • Loading branch information
Rugvip committed Mar 4, 2021
2 parents 3a680d5 + c5a4d04 commit abf64c8
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 10 deletions.
11 changes: 4 additions & 7 deletions packages/core-api/src/extensions/componentData.test.tsx
Expand Up @@ -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);
Expand Down
7 changes: 4 additions & 3 deletions packages/core-api/src/extensions/componentData.tsx
Expand Up @@ -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>,
Expand Down

0 comments on commit abf64c8

Please sign in to comment.