Skip to content

Commit 9af67bb

Browse files
fix(overmind-devtools): derived and computed notification, styling and flushes
1 parent 4cb01f5 commit 9af67bb

File tree

9 files changed

+108
-65
lines changed

9 files changed

+108
-65
lines changed

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,8 @@ import { Message, Tab } from './state'
55

66
export default (action: Action) => {
77
const onMessage = action<Message>()
8-
.mutation(mutations.addMessagesFromClient)
98
.mutation(mutations.performMutationsByMessageType)
9+
.mutation(mutations.addMessagesFromClient)
1010

1111
const loadDevtools = action()
1212
// .do(({ storage }) => storage.clear())

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

Lines changed: 23 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -51,9 +51,9 @@ export function resetNewPortValue(state: State) {
5151
}
5252

5353
export function addMessagesFromClient(state: State, message: Message) {
54-
state.apps[message.port].messages = state.apps[message.port].messages.concat(
55-
message.message
56-
)
54+
state.apps[message.port].messages = message.message
55+
.reverse()
56+
.concat(state.apps[message.port].messages)
5757
}
5858

5959
export function changeTab(state: State, tab: Tab) {
@@ -161,15 +161,16 @@ export function performMutationsByMessageType(state: State, message: Message) {
161161
state.apps[message.port].derived[clientMessage.data.path] =
162162
clientMessage.data
163163

164-
if (typeof clientMessage.data.flushId === 'number') {
165-
ensureFlushExists(
166-
state.apps[message.port].flushes,
167-
clientMessage.data.flushId
168-
)
169-
state.apps[message.port].flushes[
170-
clientMessage.data.flushId
171-
].derived.push(clientMessage.data.path)
172-
}
164+
break
165+
}
166+
case 'derived:dirty': {
167+
ensureFlushExists(
168+
state.apps[message.port].flushes,
169+
clientMessage.data.flushId
170+
)
171+
state.apps[message.port].flushes[
172+
clientMessage.data.flushId
173+
].derived.push(clientMessage.data.path)
173174
break
174175
}
175176
case 'computed': {
@@ -181,16 +182,16 @@ export function performMutationsByMessageType(state: State, message: Message) {
181182

182183
state.apps[message.port].computed[clientMessage.data.path] =
183184
clientMessage.data
184-
185-
if (typeof clientMessage.data.flushId === 'number') {
186-
ensureFlushExists(
187-
state.apps[message.port].flushes,
188-
clientMessage.data.flushId
189-
)
190-
state.apps[message.port].flushes[
191-
clientMessage.data.flushId
192-
].computed.push(clientMessage.data.path)
193-
}
185+
break
186+
}
187+
case 'computed:dirty': {
188+
ensureFlushExists(
189+
state.apps[message.port].flushes,
190+
clientMessage.data.flushId
191+
)
192+
state.apps[message.port].flushes[
193+
clientMessage.data.flushId
194+
].computed.push(clientMessage.data.path)
194195
break
195196
}
196197
case 'action:start': {

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

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,13 @@ const Components: React.SFC<Connect> = ({ app }) => (
3535
</Panel>
3636
</Panels>
3737
</div>
38-
<Table headers={['name', 'updates', 'values']}>
38+
<Table
39+
headers={[
40+
{ title: 'name', width: '150px' },
41+
{ title: 'updates', width: '100px' },
42+
{ title: 'paths', width: 'calc(100% - 250px)' },
43+
]}
44+
>
3945
{app.state.componentsMounted.map((component) => {
4046
return (
4147
<Row key={component.id}>
@@ -45,9 +51,7 @@ const Components: React.SFC<Connect> = ({ app }) => (
4551
{component.updateCount}
4652
</Text>
4753
</Cell>
48-
<Cell>
49-
{component.paths.map((path) => <Pill key={path}>{path}</Pill>)}
50-
</Cell>
54+
<Cell wordwrap="break-word">{component.paths.join(', ')}</Cell>
5155
</Row>
5256
)
5357
})}

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

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,11 +6,10 @@ import { Wrapper } from './elements'
66
class Console extends React.Component<Connect> {
77
render() {
88
const { app } = this.props
9-
const messagesReversed = app.state.currentApp.messages.slice().reverse()
109

1110
return (
1211
<Wrapper>
13-
{messagesReversed.map((message, index) => (
12+
{app.state.currentApp.messages.map((message, index) => (
1413
<ConsoleRow key={'_' + index} message={message} />
1514
))}
1615
</Wrapper>

packages/node_modules/overmind-devtools/src/components/common/Table/elements.tsx

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,17 +3,32 @@ import styled from '../../../styled-components'
33
export const TableComponent = styled.table`
44
width: 100%;
55
margin-top: ${({ theme }) => theme.padding.large};
6+
table-layout: fixed;
7+
border-collapse: collapse;
68
`
79

810
export const Headers = styled.thead``
911

10-
export const Header = styled.th`
12+
export const Header = styled<
13+
{
14+
width: string
15+
},
16+
'th'
17+
>('th')`
1118
text-align: left;
19+
width: ${({ width }) => width};
1220
font-size: ${({ theme }) => theme.fontSize.small};
1321
`
1422

1523
export const Body = styled.tbody``
1624

1725
export const RowComponent = styled.tr``
1826

19-
export const CellComponent = styled.td``
27+
export const CellComponent = styled<
28+
{
29+
wordwrap?: string
30+
},
31+
'td'
32+
>('td')`
33+
word-wrap: ${({ wordwrap }) => wordwrap || 'normal'};
34+
`

packages/node_modules/overmind-devtools/src/components/common/Table/index.tsx

Lines changed: 17 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,15 +8,24 @@ import {
88
CellComponent,
99
} from './elements'
1010

11+
type Header = {
12+
title: string
13+
width: string
14+
}
15+
1116
type TableProps = {
12-
headers: string[]
17+
headers: Header[]
1318
}
1419

1520
const Table: React.SFC<TableProps> = ({ headers, children }) => (
1621
<TableComponent>
1722
<Headers>
1823
<Row>
19-
{headers.map((header) => <Header key={header}>{header}</Header>)}
24+
{headers.map((header) => (
25+
<Header key={header.title} width={header.width}>
26+
{header.title}
27+
</Header>
28+
))}
2029
</Row>
2130
</Headers>
2231
<Body>{children}</Body>
@@ -27,8 +36,12 @@ export const Row: React.SFC = ({ children }) => (
2736
<RowComponent>{children}</RowComponent>
2837
)
2938

30-
export const Cell: React.SFC = ({ children }) => (
31-
<CellComponent>{children}</CellComponent>
39+
type CellProps = {
40+
wordwrap?: string
41+
}
42+
43+
export const Cell: React.SFC<CellProps> = ({ wordwrap, children }) => (
44+
<CellComponent wordwrap={wordwrap}>{children}</CellComponent>
3245
)
3346

3447
export default Table

packages/node_modules/overmind/src/computed.ts

Lines changed: 11 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -57,26 +57,11 @@ export class Computed {
5757
if (cache.proxyStateTreeListener) {
5858
cache.proxyStateTreeListener.update(cache.paths)
5959
} else {
60-
eventHub.emit('computed', {
61-
path,
62-
paths: Array.from(cache.paths),
63-
updateCount: cache.updateCount,
64-
value: cache.value,
65-
limit: this.cacheLimit,
66-
cacheKeysCount: this.cacheKeys.length,
67-
cacheKeyIndex: this.cacheKeys.indexOf(config),
68-
})
6960
cache.proxyStateTreeListener = proxyStateTree.addMutationListener(
7061
cache.paths,
7162
(flushId) => {
72-
eventHub.emit('computed', {
63+
eventHub.emit('computed:dirty', {
7364
path,
74-
paths: Array.from(cache.paths),
75-
updateCount: cache.updateCount,
76-
value: cache.value,
77-
limit: this.cacheLimit,
78-
cacheKeysCount: this.cacheKeys.length,
79-
cacheKeyIndex: this.cacheKeys.indexOf(config),
8065
flushId,
8166
})
8267
cache.isDirty = true
@@ -90,6 +75,16 @@ export class Computed {
9075
proxyStateTree.addTrackingPath(path)
9176
}
9277

78+
eventHub.emit('computed', {
79+
path,
80+
paths: Array.from(cache.paths),
81+
updateCount: cache.updateCount,
82+
value: cache.value,
83+
limit: this.cacheLimit,
84+
cacheKeysCount: this.cacheKeys.length,
85+
cacheKeyIndex: this.cacheKeys.indexOf(config),
86+
})
87+
9388
return cache.value
9489
} else if (cache) {
9590
return cache.value

packages/node_modules/overmind/src/derived.ts

Lines changed: 8 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -30,20 +30,11 @@ class Derived {
3030
if (this.proxyStateTreeListener) {
3131
this.proxyStateTreeListener.update(this.paths)
3232
} else {
33-
eventHub.emit('derived', {
34-
path,
35-
paths: Array.from(this.paths),
36-
updateCount: this.updateCount,
37-
value: this.value,
38-
})
3933
this.proxyStateTreeListener = proxyStateTree.addMutationListener(
4034
this.paths,
4135
(flushId) => {
42-
eventHub.emit('derived', {
36+
eventHub.emit('derived:dirty', {
4337
path,
44-
paths: Array.from(this.paths),
45-
updateCount: this.updateCount,
46-
value: this.value,
4738
flushId,
4839
})
4940
this.isDirty = true
@@ -58,6 +49,13 @@ class Derived {
5849
proxyStateTree.addTrackingPath(path)
5950
}
6051

52+
eventHub.emit('derived', {
53+
path,
54+
paths: Array.from(this.paths),
55+
updateCount: this.updateCount,
56+
value: this.value,
57+
})
58+
6159
return this.value
6260
}
6361
}

packages/node_modules/overmind/src/index.ts

Lines changed: 22 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,10 @@ export interface Events {
2525
paths: string[]
2626
updateCount: number
2727
value: any
28-
flushId?: number
28+
}
29+
'derived:dirty': {
30+
path: string
31+
flushId: number
2932
}
3033
computed: {
3134
path: string
@@ -35,7 +38,10 @@ export interface Events {
3538
limit: number
3639
cacheKeysCount: number
3740
cacheKeyIndex: number
38-
flushId?: number
41+
}
42+
'computed:dirty': {
43+
path: string
44+
flushId: number
3945
}
4046
'reaction:add': {
4147
path: string
@@ -161,7 +167,7 @@ export default class App<
161167
*/
162168
actionChain.on('operator:async', (data) => {
163169
const flushData = proxyStateTree.flush()
164-
if (this.devtools) {
170+
if (this.devtools && flushData.mutations.length) {
165171
this.devtools.send({
166172
type: 'flush',
167173
data: {
@@ -173,7 +179,7 @@ export default class App<
173179
})
174180
actionChain.on('action:end', (data) => {
175181
const flushData = proxyStateTree.flush()
176-
if (this.devtools) {
182+
if (this.devtools && flushData.mutations.length) {
177183
this.devtools.send({
178184
type: 'flush',
179185
data: {
@@ -255,12 +261,24 @@ export default class App<
255261
data,
256262
})
257263
)
264+
eventHub.on('derived:dirty', (data) =>
265+
devtools.send({
266+
type: 'derived:dirty',
267+
data,
268+
})
269+
)
258270
eventHub.on('computed', (data) =>
259271
devtools.send({
260272
type: 'computed',
261273
data,
262274
})
263275
)
276+
eventHub.on('computed:dirty', (data) =>
277+
devtools.send({
278+
type: 'computed:dirty',
279+
data,
280+
})
281+
)
264282
eventHub.on('reaction:add', (data) =>
265283
devtools.send({
266284
type: 'reaction:add',

0 commit comments

Comments
 (0)