Skip to content

Commit beec9ce

Browse files
committed
Fix local store
1 parent c0ff544 commit beec9ce

File tree

4 files changed

+21
-9
lines changed

4 files changed

+21
-9
lines changed

dev/register.js

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ const AddonPanel = ({
2828
update,
2929
theme,
3030
data,
31+
comment
3132
}) => {
3233
return (
3334
<LayoutBlock style={{ padding: 0 }}>
@@ -40,6 +41,7 @@ const AddonPanel = ({
4041
<button onClick={() => update({ themes: ['T1', 'T2', 'T3'] })}>
4142
Update
4243
</button>
44+
<button onClick={() => comment()}> comment </button>
4345
</AddonBlock>
4446
{/* <Block style={blockStyle}>
4547
<small>{JSON.stringify(api.getCurrentStoryData())}</small>
@@ -69,6 +71,10 @@ register(
6971
currentTheme: store.currentTheme - 1,
7072
})),
7173
update: global(),
74+
comment: local(store => ({
75+
...store,
76+
comment: 'comment',
77+
})),
7278
})
7379
)(AddonPanel);
7480

dev/withAdk.js

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,14 +2,16 @@ import React from 'react';
22
import { createDecorator, setParameters } from '../src/decorator';
33
import './config';
44

5-
const DecoratorUI = ({ context, getStory, theme }) => (
5+
const DecoratorUI = ({ context, getStory, theme, info }) => (
66
<div>
77
Theme: {theme} <br />
8+
Data: {info} <br />
89
{getStory(context)}
910
</div>
1011
);
1112

1213
export const withAdk = createDecorator({
1314
theme: store => store.themes[store.currentTheme],
14-
})(DecoratorUI, { isGlobal: true });
15+
info: store => JSON.stringify(store, null, 2)
16+
})(DecoratorUI, { isGlobal: false });
1517
export const adkParams = setParameters();

src/ChannelStore.js

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -160,3 +160,7 @@ export const getSingleStore = (...args) => {
160160
singleStore = singleStore || new ChannelStore(...args);
161161
return singleStore;
162162
};
163+
164+
export const getNewStore = (...args) => {
165+
return new ChannelStore(...args);
166+
};

src/withChannel.js

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import React from 'react';
22

3-
import { getSingleStore } from './ChannelStore';
3+
import { getSingleStore, getNewStore } from './ChannelStore';
44

55
const getDisplayName = WrappedComponent =>
66
WrappedComponent.displayName || WrappedComponent.name || 'Component';
@@ -42,13 +42,13 @@ const withChannel = ({
4242
this.state = {
4343
data: initStateData,
4444
selectors: isReceived ? this.prepareSelectors(initStateData) : {},
45-
isReceived,
46-
};
45+
isReceived,
46+
};
4747

48-
this.store = getSingleStore({
49-
EVENT_ID_INIT,
50-
EVENT_ID_DATA,
51-
EVENT_ID_BACK,
48+
this.store = (panel ? getSingleStore : getNewStore)({
49+
EVENT_ID_INIT,
50+
EVENT_ID_DATA,
51+
EVENT_ID_BACK,
5252
name: props.pointName,
5353
initData: this.state.data,
5454
isPanel: this.isPanel,

0 commit comments

Comments
 (0)