Skip to content

Commit e411b1f

Browse files
feat(overmind-devtools): add devtool tracking to all operators
1 parent 6e7912c commit e411b1f

File tree

8 files changed

+188
-93
lines changed

8 files changed

+188
-93
lines changed

packages/demos/react-typescript-todomvc/src/app/actions.ts

Lines changed: 25 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,41 @@
11
import * as React from 'react'
2-
import { Action } from 'overmind'
2+
import {
3+
Action,
4+
pipe,
5+
Operator,
6+
map,
7+
mutate,
8+
when,
9+
run,
10+
wait,
11+
fork,
12+
debounce,
13+
filter,
14+
forEach,
15+
} from 'overmind'
316
import { Todo } from './state'
417

518
type ChangeEvent = React.ChangeEvent<HTMLInputElement>
619

720
let nextTodoId = 0
821

22+
export const changeNewTodoTitle: Operator<ChangeEvent, any> = pipe(
23+
map(({ value }) => value.target.value),
24+
mutate(({ state, value }) => (state.newTodoTitle = value)),
25+
map(() => ['foo', 'bar', 'baz']),
26+
forEach(run(() => {})),
27+
filter(() => true),
28+
debounce(200)
29+
)
30+
31+
/*
932
export const changeNewTodoTitle: Action<ChangeEvent> = ({
1033
value: event,
1134
state,
1235
}) => {
1336
state.newTodoTitle = event.target.value
1437
}
38+
*/
1539

1640
export const addTodo: Action = ({ state }) => {
1741
state.todos.unshift({

packages/node_modules/overmind-devtools/src/app/operators.ts

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { mutate, forEach, fork, Operator, when, map } from 'overmind'
1+
import { mutate, forEach, fork, Operator, when, map, EventType } from 'overmind'
22
import {
33
Message,
44
AppMessage,
@@ -19,6 +19,7 @@ import {
1919
EndActionMessage,
2020
MutationsMessage,
2121
EffectMessage,
22+
ExecutionType,
2223
} from './types'
2324
import {
2425
createApp,
@@ -77,7 +78,10 @@ export const addFlushAndRunMutations = mutate<FlushMessage>(
7778
)
7879

7980
export const ensureApp = mutate<Message>(({ value: message, state }) => {
80-
if (!state.apps[message.appName]) {
81+
if (
82+
!state.apps[message.appName] ||
83+
message.messages[0].type === ExecutionType.INIT
84+
) {
8185
state.apps[message.appName] = createApp({
8286
name: message.appName,
8387
})

packages/node_modules/overmind-devtools/src/components/Action/elements.tsx

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,7 @@ export const Wrapper = styled.div`
66
overflow-y: scroll;
77
`
88

9-
export const Container = styled.div`
10-
border-left: 2px solid ${({ theme }) => theme.color.black};
11-
`
9+
export const Container = styled.div``
1210

1311
export const Pipe = styled.div`
1412
display: flex;

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

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ const ActionOperator: React.SFC<Props> = ({
2828
<React.Fragment key={operator.operatorId}>
2929
{value === undefined ? null : (
3030
<Pipe>
31-
<Path showPathTag={false}>
31+
<Path showPathTag={false} visible={false}>
3232
{operator.path.length ? (
3333
<Text variant="hint">
3434
<b>{operator.path.join('.')}</b>
@@ -41,7 +41,8 @@ const ActionOperator: React.SFC<Props> = ({
4141
<Pipe>
4242
<Path
4343
visible={
44-
prevOperator &&
44+
Boolean(prevOperator) &&
45+
Boolean(operator.path.length) &&
4546
prevOperator.path.join('.') !== operator.path.join('.')
4647
}
4748
borderColor={operator.type === 'mutate' ? 'red' : 'primary'}

packages/node_modules/overmind-devtools/src/components/ActionPath/elements.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ export const Path = styled<
88
'div'
99
>('div')`
1010
position: relative;
11-
min-width: 25px;
11+
height: ${({ visible }) => (visible ? '100%' : '0')}
1212
visibility: ${({ visible }) => (visible === false ? 'hidden' : 'visible')};
1313
`
1414

@@ -37,7 +37,7 @@ export const PathText = styled<
3737
>('div')`
3838
position: relative;
3939
z-index: 1;
40-
margin: ${({ theme }) => `0 ${theme.padding.smaller} 0 25px`};
40+
margin: ${({ theme }) => `0 ${theme.padding.smaller} 0 0`};
4141
padding: ${({ theme }) =>
4242
`${theme.padding.smallest} ${theme.padding.smaller}`};
4343
border: 1px solid ${({ theme, borderColor }) => theme.color[borderColor]};

packages/node_modules/overmind/src/index.test.ts

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -143,7 +143,7 @@ describe('Overmind', () => {
143143
actionId: 0,
144144
actionName: 'doThis',
145145
executionId: 0,
146-
operatorId: 0,
146+
operatorId: -1,
147147
path: [],
148148
})
149149
})
@@ -152,7 +152,7 @@ describe('Overmind', () => {
152152
actionId: 0,
153153
executionId: 0,
154154
actionName: 'doThis',
155-
operatorId: 0,
155+
operatorId: -1,
156156
path: [],
157157
})
158158
})
@@ -179,7 +179,6 @@ describe('Overmind', () => {
179179
expect(toJSON(data)).toEqual({
180180
actionId: 0,
181181
actionName: 'doThis',
182-
type: 'action',
183182
path: [],
184183
isAsync: false,
185184
executionId: 0,

0 commit comments

Comments
 (0)