Skip to content

Commit 9943492

Browse files
feat(overmind-devtools): add reactions to flushes
1 parent ad9ecfe commit 9943492

File tree

8 files changed

+30
-3
lines changed

8 files changed

+30
-3
lines changed

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

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -222,6 +222,17 @@ export const performMutationsByMessageType: Mutate<Message> = (
222222
].computed.push(clientMessage.data.path)
223223
break
224224
}
225+
case 'reaction:update': {
226+
ensureFlushExists(
227+
state.apps[message.port].flushes,
228+
clientMessage.data.flushId
229+
)
230+
231+
state.apps[message.port].flushes[
232+
clientMessage.data.flushId
233+
].reactions.push(clientMessage.data.path)
234+
break
235+
}
225236
case 'action:start': {
226237
const app = state.apps[message.port]
227238
const action = clientMessage.data

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,7 @@ export type Flush = {
6666
components: string[]
6767
derived: string[]
6868
computed: string[]
69+
reactions: string[]
6970
}
7071

7172
export type FlushReference = {

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

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import * as ColorHash from 'color-hash'
2-
import { App } from './types'
2+
import { App, Flush } from './types'
33

44
export const runMutation = (state) => (mutation) => {
55
const pathArray = mutation.path.split('.')
@@ -60,12 +60,14 @@ export const nameToColor = (name, lightness = 0.5, saturation = 0.5) => {
6060

6161
export const ensureFlushExists = (flushes, flushId) => {
6262
if (!flushes[flushId]) {
63-
flushes[flushId] = {
63+
const flush: Flush = {
6464
flushId,
6565
mutations: [],
6666
components: [],
6767
derived: [],
6868
computed: [],
69+
reactions: [],
6970
}
71+
flushes[flushId] = flush
7072
}
7173
}

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

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,9 @@ const ActionFlush: React.SFC<Props> = ({ flush, flushReference, app }) => {
3434
<Text variant="hint">
3535
<Icon>calculator</Icon> {flush.computed.length}
3636
</Text>
37+
<Text variant="hint">
38+
<Icon>flask</Icon> {flush.reactions.length}
39+
</Text>
3740
<Text variant="hint">
3841
{isExpanded ? <Icon>chevron-down</Icon> : <Icon>chevron-up</Icon>}
3942
</Text>
@@ -62,6 +65,13 @@ const ActionFlush: React.SFC<Props> = ({ flush, flushReference, app }) => {
6265
</Text>
6366
</div>
6467
))}
68+
{flush.reactions.map((reactionPath) => (
69+
<div key={reactionPath}>
70+
<Text variant="hint">
71+
<Icon>flask</Icon> {reactionPath}
72+
</Text>
73+
</div>
74+
))}
6575
</div>
6676
) : null}
6777
</Flush>

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ const icons = {
1313
calculator: '\f1ec',
1414
close: '\f00d',
1515
trash: '\f014',
16+
flask: '\f0c3',
1617
}
1718

1819
export const IconElement = styled<
112 Bytes
Binary file not shown.

packages/node_modules/overmind/src/internalTypes.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,7 @@ export interface Events {
6868
path: string
6969
statePath: string
7070
updateCount: number
71+
flushId: number
7172
}
7273
[EventType.REACTION_REMOVE]: {
7374
path: string

packages/node_modules/overmind/src/reaction.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,14 +19,15 @@ class Reaction {
1919
)[0]
2020

2121
this.proxyStateTreeListener = this.proxyStateTree.addMutationListener(
22-
(mutations) => {
22+
(mutations, flushId) => {
2323
for (let mutationIndex in mutations) {
2424
const mutation = mutations[mutationIndex]
2525
if (mutation.path.indexOf(this.statePath) === 0) {
2626
this.eventHub.emitAsync(EventType.REACTION_UPDATE, {
2727
path: this.path,
2828
statePath: this.statePath,
2929
updateCount: ++this.updateCount,
30+
flushId,
3031
})
3132
cb()
3233
}

0 commit comments

Comments
 (0)