Skip to content

Commit 4d14d13

Browse files
feat(overmind): operator factories, error operators and removed value deprecation
BREAKING CHANGE: removed value and deprecation from context
1 parent 3816c28 commit 4d14d13

File tree

19 files changed

+1114
-380
lines changed

19 files changed

+1114
-380
lines changed

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

Lines changed: 33 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -24,39 +24,42 @@ const Action: SFC = () => {
2424
>
2525
expand all
2626
</div>
27-
{state.currentAction.operators.map((operator, index) => {
28-
const prevOperator = state.currentAction.operators[index - 1]
29-
const value =
30-
index === 0 ? state.currentAction.value : prevOperator.result
31-
const flushReference =
32-
state.currentApp.flushByOperatorId[getOperatorId(operator)]
33-
const flush =
34-
flushReference && state.currentApp.flushes[flushReference.flushId]
27+
{Object.keys(state.currentAction.operators)
28+
.sort()
29+
.map((operatorId, index) => {
30+
const operator = state.currentAction.operators[operatorId]
31+
const prevOperator = state.currentAction.operators[index - 1]
32+
const value =
33+
index === 0 ? state.currentAction.value : prevOperator.result
34+
const flushReference =
35+
state.currentApp.flushByOperatorId[getOperatorId(operator)]
36+
const flush =
37+
flushReference && state.currentApp.flushes[flushReference.flushId]
38+
39+
if (flush) {
40+
return (
41+
<div key={operator.actionId + '_' + operator.operatorId}>
42+
<ActionOperator
43+
prevOperator={prevOperator}
44+
operator={operator}
45+
value={value}
46+
operatorIndex={index}
47+
/>
48+
<Flush flush={flush} />
49+
</div>
50+
)
51+
}
3552

36-
if (flush) {
3753
return (
38-
<div key={operator.actionId + '_' + operator.operatorId}>
39-
<ActionOperator
40-
prevOperator={prevOperator}
41-
operator={operator}
42-
value={value}
43-
operatorIndex={index}
44-
/>
45-
<Flush flush={flush} />
46-
</div>
54+
<ActionOperator
55+
key={operator.actionId + '_' + operator.operatorId}
56+
prevOperator={prevOperator}
57+
operator={operator}
58+
value={value}
59+
operatorIndex={index}
60+
/>
4761
)
48-
}
49-
50-
return (
51-
<ActionOperator
52-
key={operator.actionId + '_' + operator.operatorId}
53-
prevOperator={prevOperator}
54-
operator={operator}
55-
value={value}
56-
operatorIndex={index}
57-
/>
58-
)
59-
})}
62+
})}
6063
{!state.currentAction.isRunning && flush ? <Flush flush={flush} /> : null}
6164
</div>
6265
)

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

Lines changed: 3 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -187,7 +187,7 @@ export const addAction: Operator<StartActionMessage> = action(
187187
app.actions[actionId] = {
188188
...action,
189189
isRunning: true,
190-
operators: [],
190+
operators: {},
191191
hasError: false,
192192
}
193193

@@ -232,26 +232,7 @@ export const addOperator: Operator<StartOperatorMessage> = action(
232232
events: [],
233233
}
234234

235-
action.operators.push(operator)
236-
237-
/*
238-
This ensures the order of operators, as actions composed with
239-
"parallel" operator can trigger operators sync/async, adding
240-
them in wrong order
241-
*/
242-
const paths = new Map()
243-
action.operators.forEach((operator, index) => {
244-
const path = operator.path.length ? operator.path.join('.') : '__' + index
245-
if (paths.has(path)) {
246-
paths.get(path).push(operator)
247-
} else {
248-
paths.set(path, [operator])
249-
}
250-
})
251-
action.operators = Array.from(paths).reduce(
252-
(aggr, arr) => aggr.concat(arr[1]),
253-
[]
254-
)
235+
action.operators[operator.operatorId] = operator
255236
}
256237
)
257238

@@ -260,9 +241,7 @@ export const updateOperator: Operator<EndOperatorMessage> = action(
260241
const operatorData = message.data
261242
const actionId = getActionId(operatorData)
262243
const action = state.apps[message.appName].actions[actionId]
263-
const operator = action.operators.find(
264-
(operator) => getOperatorId(operatorData) === getOperatorId(operator)
265-
)
244+
const operator = action.operators[getOperatorId(operatorData)]
266245

267246
operator.isAsync = operatorData.isAsync
268247
operator.isRunning = false

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

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,9 @@ export type Action = {
7575
actionId: number
7676
executionId: number
7777
isRunning: boolean
78-
operators: Operator[]
78+
operators: {
79+
[id: string]: Operator
80+
}
7981
value: any
8082
hasError: boolean
8183
}

0 commit comments

Comments
 (0)