Skip to content

Commit 4e3b2a8

Browse files
Fix container deleting global stores (#106)
1 parent 8d2f22e commit 4e3b2a8

File tree

2 files changed

+11
-2
lines changed

2 files changed

+11
-2
lines changed

src/components/__tests__/container.test.js

+10-1
Original file line numberDiff line numberDiff line change
@@ -173,13 +173,14 @@ describe('Container', () => {
173173
expect(mockOnContainerCleanupInner).toHaveBeenCalledTimes(1);
174174
});
175175

176-
it('should not cleanup from global on unmount if still listeners', () => {
176+
it('should not cleanup from global on unmount if still listeners', async () => {
177177
storeStateMock.subscribe.mockReturnValue(jest.fn());
178178
storeStateMock.listeners.mockReturnValue([jest.fn()]);
179179
const Subscriber = createSubscriber(Store);
180180
const children = <Subscriber>{() => null}</Subscriber>;
181181
const wrapper = mount(<Container scope="s1">{children}</Container>);
182182
wrapper.unmount();
183+
await Promise.resolve();
183184
expect(defaultRegistry.deleteStore).not.toHaveBeenCalled();
184185
});
185186

@@ -193,6 +194,14 @@ describe('Container', () => {
193194
expect(defaultRegistry.deleteStore).toHaveBeenCalledWith(Store, 's1');
194195
});
195196

197+
it('should not cleanup from global on unmount if not scoped', async () => {
198+
storeStateMock.listeners.mockReturnValue([]);
199+
const wrapper = mount(<Container isGlobal>Content</Container>);
200+
wrapper.unmount();
201+
await Promise.resolve();
202+
expect(defaultRegistry.deleteStore).not.toHaveBeenCalled();
203+
});
204+
196205
it('should call Container onInit on first render', () => {
197206
const Subscriber = createSubscriber(Store);
198207
const renderPropChildren = jest.fn().mockReturnValue(null);

src/components/container.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -161,7 +161,7 @@ export default class Container extends Component {
161161
deleteScopedStore(scopeId = this.props.scope) {
162162
const { storeType } = this.constructor;
163163
const { storeState } = this.getScopedStore(storeType, scopeId);
164-
if (!storeState.listeners().length) {
164+
if (scopeId != null && !storeState.listeners().length) {
165165
this.getRegistry().deleteStore(storeType, scopeId);
166166
}
167167
}

0 commit comments

Comments
 (0)