Skip to content

Commit 6a50a9c

Browse files
feat(overmind): actions return value and runs sync and async
BREAKING CHANGE: actions now returns value and runs sync async
1 parent 28ddbfb commit 6a50a9c

File tree

27 files changed

+448
-322
lines changed

27 files changed

+448
-322
lines changed

package-lock.json

Lines changed: 3 additions & 3 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,7 @@
5858
},
5959
"devDependencies": {
6060
"@babel/core": "7.2.2",
61+
"@babel/plugin-proposal-class-properties": "7.3.4",
6162
"@babel/plugin-transform-react-jsx": "7.1.6",
6263
"@babel/preset-react": "7.0.0",
6364
"@babel/preset-typescript": "7.1.0",
@@ -100,15 +101,14 @@
100101
"ts-jest": "23.10.4",
101102
"ts-loader": "4.4.2",
102103
"tslib": "1.9.3",
103-
"typescript": "3.3.1",
104+
"typescript": "^3.4.5",
104105
"typescript-eslint-parser": "^21.0.1",
105106
"url-loader": "1.0.1",
106107
"vue": "2.5.16",
107108
"vue-template-compiler": "2.5.16",
108109
"webpack": "4.28.4",
109110
"webpack-cli": "3.1.2",
110-
"webpack-dev-server": "3.1.11",
111-
"@babel/plugin-proposal-class-properties": "7.3.4"
111+
"webpack-dev-server": "3.1.11"
112112
},
113113
"lint-staged": {
114114
"*.{js,ts,tsx}": [

packages/node_modules/overmind-devtools/src/components/Apps/styles.ts

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ import { colors } from '../../theme'
44
export const wrapper = css({
55
position: 'relative',
66
display: 'flex',
7-
paddingTop: '0.5rem',
7+
marginTop: '0.5rem',
88
backgroundColor: colors.dark,
99
height: 50,
1010
justifyContent: 'center',
@@ -17,7 +17,10 @@ export const app = css({
1717
border: 0,
1818
width: '100%',
1919
cursor: 'pointer',
20-
backgroundColor: colors.white,
20+
backgroundColor: colors.dark,
21+
borderRadiusTopRight: 3,
22+
borderRadiusBottomRight: 3,
23+
boxShadow: '5px 5px 20px 5px rgba(0,0,0,0.10)',
2124
display: 'flex',
2225
alignItems: 'center',
2326
color: colors.black,
@@ -26,7 +29,8 @@ export const app = css({
2629
})
2730

2831
export const appSelected = css({
29-
backgroundColor: colors.white2,
32+
fontWeight: 'bold',
33+
color: colors.white,
3034
})
3135

3236
export const currentApp = (color: string) =>
@@ -55,9 +59,9 @@ export const overlay = css({
5559

5660
export const appsList = css({
5761
position: 'absolute',
58-
left: 'calc(100% + 1px)',
62+
left: '100%',
5963
top: 0,
60-
backgroundColor: colors.white,
64+
color: colors.white,
6165
borderRight: `1px solid ${colors.dark2}`,
6266
borderBottom: `1px solid ${colors.dark2}`,
6367
})

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

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,8 @@ const Devtools: FunctionComponent = () => {
7171
<h1>Waiting for an app to connect...</h1>
7272
<h2>or</h2>
7373
<input
74-
disabled={state.runtimeLoading}
74+
autoFocus
75+
disabled={state.runtimeHost && state.runtimeLoading}
7576
className={styles.input}
7677
defaultValue={
7778
state.runtimeHost ? state.runtimeHost.split('?')[0] : ''
Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
import { createElement, FunctionComponent, Fragment, useState } from 'react'
2+
import { useOvermind } from 'overmind-devtools/src/overmind'
3+
import * as styles from './styles'
4+
import { colors } from 'overmind-devtools/src/theme'
5+
6+
const RuntimeConfig: FunctionComponent = () => {
7+
const { state, actions } = useOvermind()
8+
const currentHost = state.runtimeHost.split('?')[0]
9+
const [host, setHost] = useState(currentHost)
10+
11+
return (
12+
<div className={styles.wrapper}>
13+
<div
14+
className={styles.overlay}
15+
onClick={() => actions.toggleRuntimeConfig()}
16+
/>
17+
<form
18+
className={styles.contentWrapper}
19+
onSubmit={(event) => {
20+
event.preventDefault()
21+
host === currentHost
22+
? actions.disconnectRuntime()
23+
: actions.setRuntimeHost(host)
24+
}}
25+
>
26+
<input
27+
autoFocus
28+
value={host}
29+
onChange={(event) => setHost(event.currentTarget.value)}
30+
className={styles.input}
31+
/>
32+
<button
33+
type="submit"
34+
className={styles.button}
35+
disabled={!host.length}
36+
style={{
37+
color: host && host === currentHost ? colors.white : colors.dark,
38+
backgroundColor: host
39+
? host === currentHost
40+
? colors.red
41+
: colors.green
42+
: colors.gray,
43+
}}
44+
>
45+
{host && host === currentHost ? 'disconnect' : 'connect'}
46+
</button>
47+
</form>
48+
</div>
49+
)
50+
}
51+
52+
export default RuntimeConfig
Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
import { css } from 'emotion'
2+
import { colors } from 'overmind-devtools/src/theme'
3+
4+
export const wrapper = css({
5+
position: 'absolute',
6+
left: '100%',
7+
height: '100%',
8+
zIndex: 999999,
9+
top: 0,
10+
})
11+
12+
export const overlay = css({
13+
position: 'fixed',
14+
top: 0,
15+
left: 0,
16+
width: '100vw',
17+
height: '100vh',
18+
})
19+
20+
export const contentWrapper = css({
21+
position: 'absolute',
22+
top: 0,
23+
left: 0,
24+
height: '100%',
25+
padding: '0.5rem',
26+
boxSizing: 'border-box',
27+
display: 'flex',
28+
backgroundColor: colors.dark,
29+
borderRadiusTopRight: 3,
30+
borderRadiusBottomRight: 3,
31+
boxShadow: '5px 5px 20px 5px rgba(0,0,0,0.10)',
32+
})
33+
34+
export const input = css({
35+
border: 0,
36+
outline: 'none',
37+
padding: '0.5rem',
38+
fontSize: 18,
39+
borderRadius: 3,
40+
})
41+
42+
export const button = css({
43+
border: 0,
44+
borderRadius: 3,
45+
outline: 'none',
46+
cursor: 'pointer',
47+
marginLeft: '0.5rem',
48+
})

packages/node_modules/overmind-devtools/src/components/Tabs/index.tsx

Lines changed: 21 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -15,11 +15,13 @@ import {
1515
FaChrome,
1616
} from 'react-icons/fa'
1717
import { colors } from 'overmind-devtools/src/theme'
18+
import RuntimeConfig from 'overmind-devtools/src/components/RuntimeConfig'
1819

1920
const Tabs: FunctionComponent = () => {
2021
const { state, actions } = useOvermind()
2122

2223
function getRuntimeColor() {
24+
if (!state.runtimeHost) return colors.white
2325
if (state.runtimeError) return colors.red
2426
if (state.runtimeLoading) return colors.yellow
2527

@@ -30,27 +32,32 @@ const Tabs: FunctionComponent = () => {
3032
<div className={styles.wrapper}>
3133
<Apps />
3234
<div className={styles.divider} />
33-
<Tooltip text="Runtime">
34-
<button className={css(styles.button, styles.activeButton)}>
35+
<div className={styles.runtimeWrapper}>
36+
<button
37+
className={css(
38+
styles.button,
39+
Boolean(state.runtimeHost) && styles.activeButton
40+
)}
41+
onClick={() => actions.toggleRuntimeConfig()}
42+
>
3543
<FaChrome
3644
style={{
3745
color: getRuntimeColor(),
3846
}}
3947
/>
4048
</button>
41-
</Tooltip>
49+
{state.isShowingRuntimeConfig ? <RuntimeConfig /> : null}
50+
</div>
4251
<div className={styles.divider} />
43-
<Tooltip text="State">
44-
<button
45-
className={css(
46-
styles.button,
47-
state.currentTab === Tab.State && styles.activeButton
48-
)}
49-
onClick={() => actions.changeTab(Tab.State)}
50-
>
51-
<FaDatabase />
52-
</button>
53-
</Tooltip>
52+
<button
53+
className={css(
54+
styles.button,
55+
state.currentTab === Tab.State && styles.activeButton
56+
)}
57+
onClick={() => actions.changeTab(Tab.State)}
58+
>
59+
<FaDatabase />
60+
</button>
5461
<Tooltip text="Actions">
5562
<button
5663
className={css(

packages/node_modules/overmind-devtools/src/components/Tabs/styles.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,14 @@
11
import { css } from 'emotion'
22
import { colors } from '../../theme'
33

4+
export const runtimeWrapper = css({
5+
position: 'relative',
6+
})
47
export const wrapper = css({
58
backgroundColor: colors.dark,
69
width: 50,
710
borderRight: `1px solid ${colors.dark3}`,
11+
boxShadow: '5px 0px 20px 5px rgba(0,0,0,0.10)',
812
})
913

1014
export const button = css({

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

Lines changed: 27 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -10,22 +10,6 @@ import {
1010
import * as o from './operators'
1111
import { isValidJson } from './utils'
1212

13-
export const onInitialize: OnInitialize = async ({ state, effects }, app) => {
14-
const port = await effects.storage.get<string>('currentPort')
15-
const runtimeHost = await effects.storage.get<string>('runtimeHost')
16-
17-
if (port) {
18-
state.port = port
19-
}
20-
21-
if (runtimeHost) {
22-
state.runtimeHost = runtimeHost
23-
}
24-
25-
effects.connector.onMessage(app.actions.onMessage)
26-
effects.connector.connect(state.port)
27-
}
28-
2913
export const onMessage: Operator<Message> = pipe(
3014
o.isPortExistsMessage({
3115
true: o.setPortExists(),
@@ -58,11 +42,13 @@ export const onMessage: Operator<Message> = pipe(
5842
})
5943
)
6044

61-
export const setError: Action<string> = ({ state }, error) =>
62-
(state.error = error)
45+
export const setError: Action<string> = ({ state }, error) => {
46+
state.error = error
47+
}
6348

64-
export const changeNewPortValue: Action<string> = ({ state }, port) =>
65-
(state.newPortValue = String(Number(port)))
49+
export const changeNewPortValue: Action<string> = ({ state }, port) => {
50+
state.newPortValue = String(Number(port))
51+
}
6652

6753
export const addConnection: Action = ({ state, effects }) => {
6854
state.error = null
@@ -122,11 +108,13 @@ export const selectApp: Action<string> = ({ state }, appName) => {
122108
state.showApps = false
123109
}
124110

125-
export const toggleShowApps: Action = ({ state }) =>
126-
(state.showApps = !state.showApps)
111+
export const toggleShowApps: Action = ({ state }) => {
112+
state.showApps = !state.showApps
113+
}
127114

128-
export const toggleCollapsedComponent: Action<Component> = (_, component) =>
129-
(component.isCollapsed = !component.isCollapsed)
115+
export const toggleCollapsedComponent: Action<Component> = (_, component) => {
116+
component.isCollapsed = !component.isCollapsed
117+
}
130118

131119
export const toggleQueryingAction: Action = ({ state }) => {
132120
state.currentApp.isQueryingAction = !state.currentApp.isQueryingAction
@@ -207,10 +195,14 @@ export const submitState: Action<string> = ({ state, effects }, newState) => {
207195
}
208196

209197
export const setRuntimeHost: Action<string> = ({ state, effects }, host) => {
198+
if (!host.startsWith('http://') && !host.startsWith('https://')) {
199+
host = 'http://' + host
200+
}
201+
210202
const uniqueHost = `${host}?overmind_runtime=${Date.now()}`
211203

212204
state.runtimeHost = uniqueHost
213-
205+
state.isShowingRuntimeConfig = false
214206
effects.storage.set('runtimeHost', uniqueHost)
215207
}
216208

@@ -231,3 +223,13 @@ export const runtimeError: Action<string> = ({ state }, message) => {
231223
state.runtimeLoading = false
232224
state.runtimeConnected = false
233225
}
226+
227+
export const toggleRuntimeConfig: Action = ({ state }) => {
228+
state.isShowingRuntimeConfig = !state.isShowingRuntimeConfig
229+
}
230+
231+
export const disconnectRuntime: Action = ({ state, effects }) => {
232+
state.runtimeHost = ''
233+
state.isShowingRuntimeConfig = false
234+
effects.storage.set('runtimeHost', '')
235+
}

packages/node_modules/overmind-devtools/src/overmind/index.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,10 @@ import { createHook } from 'overmind-react'
44
import * as actions from './actions'
55
import * as effects from './effects'
66
import state from './state'
7+
import onInitialize from './onInitialize'
78

89
const config = {
9-
onInitialize: actions.onInitialize,
10+
onInitialize,
1011
effects,
1112
actions,
1213
state,

0 commit comments

Comments
 (0)