Skip to content

Commit 7fe58db

Browse files
feat(overmind-devtools-client): hit metaKey and r to refresh the app
1 parent eb424af commit 7fe58db

File tree

5 files changed

+25
-30
lines changed

5 files changed

+25
-30
lines changed

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

Lines changed: 15 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,26 @@
1-
import { createElement, FunctionComponent, Fragment } from 'react'
1+
import { createElement, FunctionComponent, Fragment, useEffect } from 'react'
22
import { useOvermind } from '../../overmind'
33
import * as styles from './styles'
44
import * as text from '../../styles/text'
55
import { colors } from '../../theme'
6-
import Input from '../common/Input'
7-
import Button from '../common/Button'
86
import Workspace from '../Workspace'
97
import { css } from 'emotion'
108

119
const Devtools: FunctionComponent = () => {
12-
const { state } = useOvermind()
10+
const { state, actions } = useOvermind()
11+
12+
useEffect(() => {
13+
const listener = (event: KeyboardEvent) => {
14+
if (event.metaKey && event.keyCode === 82) {
15+
actions.refreshApp()
16+
}
17+
}
18+
document.addEventListener('keydown', listener)
19+
20+
return () => {
21+
document.removeEventListener('keydown', listener)
22+
}
23+
}, [])
1324

1425
if (state.error) {
1526
return (

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

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -194,3 +194,7 @@ export const submitState: Action<string> = ({ state, effects }, newState) => {
194194
export const toggleRuntimeConfig: Action = ({ state }) => {
195195
state.isShowingRuntime = !state.isShowingRuntime
196196
}
197+
198+
export const refreshApp: Action = ({ state, effects }) => {
199+
effects.connector.sendMessage(state.currentAppName, 'refresh')
200+
}

packages/node_modules/overmind/src/Devtools.ts

Lines changed: 0 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -106,31 +106,6 @@ export class Devtools {
106106
this.reconnect(host, onMessage)
107107
}
108108
}
109-
110-
if (window.parent) {
111-
window.parent.postMessage(
112-
{
113-
type: 'overmind:devtools:ready',
114-
},
115-
'*'
116-
)
117-
window.addEventListener('error', () => {
118-
window.parent.postMessage(
119-
{
120-
type: 'overmind:devtools:error',
121-
},
122-
'*'
123-
)
124-
})
125-
window.addEventListener('unload', () => {
126-
window.parent.postMessage(
127-
{
128-
type: 'overmind:devtools:reload',
129-
},
130-
'*'
131-
)
132-
})
133-
}
134109
}
135110
private reconnect(host, onMessage) {
136111
setTimeout(

packages/node_modules/overmind/src/index.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -711,6 +711,9 @@ export class Overmind<ThisConfig extends IConfiguration>
711711
}
712712

713713
switch (message.type) {
714+
case 'refresh':
715+
location.reload(true)
716+
break
714717
case 'executeAction':
715718
const action = message.data.name
716719
.split('.')

packages/overmind-website/src/index.tsx

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,9 @@ const overmind = createOvermind(
1414
? {
1515
devtools: false,
1616
}
17-
: {}
17+
: {
18+
devtools: 'localhost:3032',
19+
}
1820
)
1921
setConfig({
2022
ignoreSFC: true, // RHL will be __completely__ disabled for SFC

0 commit comments

Comments
 (0)