Skip to content

Commit 1f67f81

Browse files
feat(overmind-devtools-client): improve editing state and passing action payload
1 parent 1f7d24b commit 1f67f81

File tree

7 files changed

+24
-17
lines changed

7 files changed

+24
-17
lines changed

packages/node_modules/overmind-devtools-client/src/components/ActionPayload/index.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ const ActionPayload: FunctionComponent = () => {
3131
}
3232
placeholder={
3333
state.currentApp.selectedActionQuery
34-
? 'Add some JSON payload...'
34+
? 'Add some payload...'
3535
: null
3636
}
3737
onKeyDown={(event) => {

packages/node_modules/overmind-devtools-client/src/components/Inspector/index.tsx

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -132,16 +132,19 @@ const EditValue: FunctionComponent<EditValueProps> = ({ value, onSubmit }) => {
132132
autoFocus
133133
value={state}
134134
onChange={(event) => setState(event.currentTarget.value)}
135+
onKeyDown={(event) => {
136+
if (event.metaKey && event.keyCode === 13) {
137+
onSubmit(state)
138+
}
139+
}}
135140
className={styles.newState}
136141
style={{
137142
borderColor: isValid ? null : colors.red,
138143
}}
139144
/>
140-
{isValid ? (
141-
<button onClick={() => onSubmit(state)} className={styles.ok}>
142-
OK
143-
</button>
144-
) : null}
145+
<span className={styles.ok}>
146+
CMD/CTRL + ENTER to save
147+
</span>
145148
</div>
146149
</span>
147150
)

packages/node_modules/overmind-devtools-client/src/components/Inspector/styles.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -105,10 +105,10 @@ export const ok = css({
105105
cursor: 'pointer',
106106
top: 0,
107107
right: 0,
108+
fontSize: 10,
108109
border: 0,
109110
outline: 'none',
110-
borderTopRightRadius: 3,
111-
padding: '0.5rem 1rem',
112-
backgroundColor: colors.green,
113-
color: colors.foreground,
111+
padding: '0.25rem 0.5rem',
112+
opacity: 0.5,
113+
color: colors.background,
114114
})

packages/node_modules/overmind-devtools-client/src/overmind/actions.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -221,7 +221,7 @@ export const submitState: Action<string> = ({ state, effects }, newState) => {
221221

222222
export const setAppHost: Action<string> = ({ state, effects }, host) => {
223223
state.isConnecting = true
224-
224+
225225
let fullHost = host
226226
if (host) {
227227
fullHost = host.startsWith('http') ? host : `http://${host}`

packages/node_modules/overmind-devtools-client/src/overmind/utils.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -96,7 +96,8 @@ export const getAppShortName = (name: string) => {
9696

9797
export const isValidJson = (payload: string) => {
9898
try {
99-
JSON.parse(`{ "value": ${payload} }`)
99+
// eslint-disable-next-line
100+
JSON.stringify(eval(`(function () { return ${payload} })()`))
100101

101102
return true
102103
} catch (e) {

packages/node_modules/overmind/src/Devtools.ts

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,14 @@ export class Devtools {
2929
host = host || 'localhost:3031'
3030

3131
this.ws = new WebSocket(`ws://${host}?name=${this.name}`)
32-
this.ws.onmessage = (event) => onMessage(JSON.parse(event.data))
32+
this.ws.onmessage = (event) => {
33+
const data = JSON.parse(event.data)
34+
35+
if (data.appName !== this.name) {
36+
return
37+
}
38+
onMessage(data)
39+
}
3340
this.ws.onopen = () => {
3441
this.isConnected = true
3542
this.sendBuffer()

packages/node_modules/overmind/src/index.ts

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -770,10 +770,6 @@ export class Overmind<ThisConfig extends IConfiguration>
770770
devtools.connect(
771771
host,
772772
(message: DevtoolsMessage) => {
773-
if (message.appName !== name) {
774-
return
775-
}
776-
777773
switch (message.type) {
778774
case 'refresh':
779775
location.reload(true)

0 commit comments

Comments
 (0)