Skip to content

Commit 85f45ce

Browse files
Merge pull request cerebral#130 from cerebral/onlyContext
Only context
2 parents 8b7a92d + 91b0929 commit 85f45ce

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

69 files changed

+6866
-6809
lines changed

package-lock.json

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

package.json

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -62,17 +62,17 @@
6262
"concurrently": "3.6.1",
6363
"cz-customizable": "^5.2.0",
6464
"cz-customizable-ghooks": "^1.5.0",
65-
"eslint": "^5.0.1",
66-
"eslint-config-prettier": "^2.9.0",
67-
"eslint-config-standard": "^11.0.0",
68-
"eslint-config-standard-jsx": "^5.0.0",
69-
"eslint-plugin-import": "^2.13.0",
70-
"eslint-plugin-node": "^6.0.1",
71-
"eslint-plugin-prettier": "^2.6.1",
72-
"eslint-plugin-promise": "^3.8.0",
73-
"eslint-plugin-react": "^7.10.0",
74-
"eslint-plugin-standard": "^3.1.0",
75-
"eslint-plugin-typescript": "^0.12.0",
65+
"eslint": "^5.8.0",
66+
"eslint-config-prettier": "^3.1.0",
67+
"eslint-config-standard": "^12.0.0",
68+
"eslint-config-standard-jsx": "^6.0.2",
69+
"eslint-plugin-import": "^2.14.0",
70+
"eslint-plugin-node": "^8.0.0",
71+
"eslint-plugin-prettier": "^3.0.0",
72+
"eslint-plugin-promise": "^4.0.1",
73+
"eslint-plugin-react": "^7.11.1",
74+
"eslint-plugin-standard": "^4.0.0",
75+
"eslint-plugin-typescript": "^0.13.0",
7676
"html-webpack-plugin": "3.2.0",
7777
"husky": "^0.14.3",
7878
"jest": "23.5.0",
Lines changed: 20 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,27 @@
11
import * as React from 'react'
22
import { Action } from 'overmind'
3-
import * as mutations from './mutations'
4-
import * as operations from './operations'
5-
import { Todo } from './state'
63

74
type ChangeEvent = React.ChangeEvent<HTMLInputElement>
85

9-
export const changeNewTodoTitle: Action<ChangeEvent, string> = (action) =>
10-
action.map(operations.getEventValue).mutate(mutations.setNewTodoTitle)
6+
let nextTodoId = 0
117

12-
export const addTodo: Action<React.FormEvent> = (action) =>
13-
action
14-
.run(operations.preventEventDefault)
15-
.mutate(mutations.addTodo)
16-
.mutate(mutations.clearNewTodoTitle)
8+
export const changeNewTodoTitle: Action<ChangeEvent> = ({
9+
value: event,
10+
state,
11+
}) => {
12+
state.newTodoTitle = event.target.value
13+
}
1714

18-
export const toggleCompleted: Action<Todo> = ({ mutate }) =>
19-
mutate(mutations.toggleCompleted)
15+
export const addTodo: Action = ({ state }) => {
16+
state.todos.unshift({
17+
id: String(nextTodoId++),
18+
title: state.newTodoTitle,
19+
completed: false,
20+
})
21+
state.newTodoTitle = ''
22+
}
23+
24+
export const toggleCompleted: Action<string> = ({ value: todoId, state }) => {
25+
const todo = state.todos.find((todo) => todo.id === todoId)
26+
todo.completed = !todo.completed
27+
}

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,13 +6,13 @@ import * as effects from './effects'
66
import * as state from './state'
77

88
const config = {
9-
effects,
109
actions,
10+
effects,
1111
state,
1212
}
1313

1414
declare module 'overmind' {
15-
interface App extends TApp<typeof config> {}
15+
interface IApp extends TApp<typeof config> {}
1616
}
1717

1818
export const app = new Overmind(config)

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

Lines changed: 0 additions & 20 deletions
This file was deleted.

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

Lines changed: 0 additions & 11 deletions
This file was deleted.

packages/demos/react-typescript-todomvc/src/components/AddTodo/index.tsx

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,12 @@ import { Wrapper, Input, Button, Form } from './elements'
44

55
const AddTodo: React.SFC<Connect> = ({ app }) => (
66
<Wrapper>
7-
<Form onSubmit={app.actions.addTodo}>
7+
<Form
8+
onSubmit={(event) => {
9+
event.preventDefault()
10+
app.actions.addTodo()
11+
}}
12+
>
813
<Input
914
placeholder="I need to..."
1015
value={app.state.newTodoTitle}

packages/demos/react-typescript-todomvc/src/components/Todo/index.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ type Props = {
88
} & Connect
99

1010
const Todo: React.SFC<Props> = ({ todo, app }) => (
11-
<Item onClick={() => app.actions.toggleCompleted(todo)}>
11+
<Item onClick={() => app.actions.toggleCompleted(todo.id)}>
1212
<Completed completed={todo.completed}></Completed> {todo.title}
1313
</Item>
1414
)

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

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
import { ipcRenderer } from 'electron'
22

3-
import { AppMessage } from './app/types'
3+
import { AppMessage, AppMessageType } from './app/types'
44

55
type Message = {
66
appName: string
7-
messages: AppMessage[]
7+
messages: AppMessage<any>[]
88
}
99

1010
type MessageCallback = (message: Message) => void
@@ -15,20 +15,20 @@ export class BackendConnector {
1515
constructor() {
1616
ipcRenderer.on('port:exists', this.onPortExists)
1717
}
18-
connect(port: string, messageCallback: MessageCallback) {
19-
this.messageCallback = messageCallback
18+
connect(port: string) {
2019
ipcRenderer.send('connect', port)
21-
ipcRenderer.on('message', this.onMessage)
2220
}
23-
onMessage = (_, message) => {
24-
this.messageCallback(message)
21+
onMessage = (onMessage: MessageCallback) => {
22+
this.messageCallback = onMessage
23+
ipcRenderer.on('message', (_, message) => onMessage(message))
2524
}
2625
onPortExists = (_) => {
2726
this.messageCallback({
2827
appName: null,
2928
messages: [
3029
{
31-
type: 'PORT_EXISTS',
30+
appName: '',
31+
type: AppMessageType.PORT_EXISTS,
3232
data: null,
3333
},
3434
],
Lines changed: 138 additions & 49 deletions
Original file line numberDiff line numberDiff line change
@@ -1,67 +1,156 @@
1-
import { Action } from 'overmind'
2-
import * as mutations from './mutations'
3-
import * as operations from './operations'
4-
import { Message, Tab } from './types'
1+
import { Action, pipe, OnInitialize, Pipe } from 'overmind'
2+
import {
3+
Message,
4+
Tab,
5+
AppMessageType,
6+
ExecutionType,
7+
ActionsListItemType,
8+
} from './types'
9+
import {
10+
forkEachMessage,
11+
ensureCurrentApp,
12+
addFlushAndRunMutations,
13+
updateComponent,
14+
addComponent,
15+
removeComponent,
16+
updateDerived,
17+
updateFlushWithDerived,
18+
addAction,
19+
addOperator,
20+
updateFlushWithReactionUpdate,
21+
updateOperator,
22+
updateAction,
23+
addMutations,
24+
addEffect,
25+
setPortExists,
26+
isPortExistsMessage,
27+
getMessages,
28+
addState,
29+
ensureApp,
30+
addClientMessages,
31+
} from './operators'
532

6-
const handleClientMessages: Action<Message> = (action) =>
7-
action
8-
.mutate(mutations.ensureCurrentApp)
9-
.mutate(mutations.performMutationsByMessageType)
10-
.mutate(mutations.addMessagesFromClient)
33+
export const onInitialize: OnInitialize = async ({
34+
value: actions,
35+
state,
36+
storage,
37+
connector,
38+
}) => {
39+
const port = await storage.get<string>('currentPort')
40+
if (port) {
41+
state.port = port
42+
}
43+
connector.onMessage(actions.onMessage)
44+
connector.connect(state.port)
45+
}
1146

12-
const setPortExists: Action<Message> = (action) =>
13-
action.mutate(mutations.setPortExists)
47+
const handleClientMessage: Pipe<Message> = pipe(
48+
ensureCurrentApp,
49+
ensureApp,
50+
addClientMessages,
51+
getMessages,
52+
forkEachMessage({
53+
[AppMessageType.PORT_EXISTS]: setPortExists,
54+
[ExecutionType.INIT]: addState,
55+
[ExecutionType.FLUSH]: addFlushAndRunMutations,
56+
[ExecutionType.DERIVED]: updateDerived,
57+
[ExecutionType.MUTATIONS]: addMutations,
58+
[ExecutionType.EFFECT]: addEffect,
59+
[ExecutionType.COMPONENT_ADD]: addComponent,
60+
[ExecutionType.COMPONENT_UPDATE]: updateComponent,
61+
[ExecutionType.COMPONENT_REMOVED]: removeComponent,
62+
[ExecutionType.DERIVED_DIRTY]: updateFlushWithDerived,
63+
[ExecutionType.REACTION_UPDATE]: updateFlushWithReactionUpdate,
64+
[ExecutionType.ACTION_START]: addAction,
65+
[ExecutionType.OPERATOR_START]: addOperator,
66+
[ExecutionType.OPERATOR_END]: updateOperator,
67+
[ExecutionType.ACTION_END]: updateAction,
68+
})
69+
)
1470

15-
const onMessage: Action<Message> = (action) =>
16-
action.when(operations.isPortExistsMessage, {
71+
export const onMessage: Pipe<Message> = pipe(
72+
isPortExistsMessage({
1773
true: setPortExists,
18-
false: handleClientMessages,
74+
false: handleClientMessage,
1975
})
76+
)
2077

21-
export const loadDevtools: Action = (action) =>
22-
action
23-
// .run(({ storage }) => storage.clear())
24-
.map(operations.getCurrentPortFromStorage)
25-
.mutate(mutations.setPort)
26-
.run(operations.connectCurrentPort(onMessage(action as any)))
78+
export const setError: Action<string> = ({ value: error, state }) =>
79+
(state.error = error)
2780

28-
export const setError: Action<string> = ({ mutate }) =>
29-
mutate(mutations.setError)
81+
export const changeNewPortValue: Action<string> = ({ value: port, state }) =>
82+
(state.newPortValue = String(Number(port)))
3083

31-
export const changeNewPortValue: Action<string> = (action) =>
32-
action.map(operations.toNumber).mutate(mutations.setNewPortValue)
84+
export const addConnection: Action = ({ state, connector }) => {
85+
state.error = null
86+
state.isConnecting = true
87+
state.port = state.newPortValue
88+
state.newPortValue = ''
89+
connector.connect(state.port)
90+
}
3391

34-
export const addConnection: Action = (action) =>
35-
action
36-
.mutate(mutations.setConnecting)
37-
.map(operations.getNewPortFromState)
38-
.mutate(mutations.setPort)
39-
.mutate(mutations.resetNewPortValue)
40-
.run(operations.connectCurrentPort(onMessage))
92+
export const changeTab: Action<Tab> = ({ value: tab, state }) =>
93+
(state.currentTab = tab)
4194

42-
export const changeTab: Action<Tab> = ({ mutate }) =>
43-
mutate(mutations.changeTab)
95+
export const toggleExpandState: Action<string[]> = ({ value: path, state }) => {
96+
const pathString = path.join('.')
4497

45-
export const toggleExpandState: Action<string[]> = ({ mutate }) =>
46-
mutate(mutations.toggleExpandStatePath)
98+
if (state.expandedStatePaths.indexOf(pathString) >= 0) {
99+
state.expandedStatePaths.splice(
100+
state.expandedStatePaths.indexOf(pathString),
101+
1
102+
)
103+
} else {
104+
state.expandedStatePaths = state.expandedStatePaths.concat(pathString)
105+
}
106+
}
47107

48-
export const selectAction: Action<string> = ({ mutate }) =>
49-
mutate(mutations.toggleActionItemCollapse).mutate(mutations.selectAction)
108+
export const selectAction: Action<string> = ({ value: actionId, state }) => {
109+
for (let index in state.currentApp.actionsList) {
110+
const item = state.currentApp.actionsList[index]
111+
if (
112+
item.type === ActionsListItemType.GROUP &&
113+
item.id === actionId &&
114+
state.currentApp.currentActionId === actionId
115+
) {
116+
item.isCollapsed = !item.isCollapsed
117+
break
118+
}
119+
}
120+
state.currentApp.currentActionId = actionId
121+
}
50122

51-
type Collapsed = {
52-
isCollapsed: boolean
123+
export const toggleCollapsedFlush: Action<number> = ({ value: id, state }) => {
124+
if (!state.expandAllActionDetails) {
125+
state.currentApp.flushes[id].isCollapsed = !state.currentApp.flushes[id]
126+
.isCollapsed
127+
}
53128
}
54129

55-
export const toggleCollapsedActionItem: Action<Collapsed> = (action) =>
56-
action
57-
.filter(operations.isNotExpandingAllActions)
58-
.mutate(mutations.toggleCollapsed)
130+
export const toggleCollapsedOperator: Action<number> = ({
131+
value: operatorIndex,
132+
state,
133+
}) => {
134+
if (!state.expandAllActionDetails) {
135+
const operator = state.currentAction.operators[operatorIndex]
136+
operator.isCollapsed = !operator.isCollapsed
137+
}
138+
}
59139

60-
export const toggleGroupedComponent: Action<string> = (action) =>
61-
action.mutate(mutations.toggleGroupedComponent)
140+
export const toggleGroupedComponent: Action<string> = ({
141+
value: name,
142+
state,
143+
}) => {
144+
const index = state.expandedComponents.indexOf(name)
145+
if (index === -1) {
146+
state.expandedComponents.push(name)
147+
} else {
148+
state.expandedComponents.splice(index, 1)
149+
}
150+
}
62151

63-
export const selectApp: Action<string> = (action) =>
64-
action.mutate(mutations.selectApp)
152+
export const selectApp: Action<string> = ({ value: appName, state }) =>
153+
(state.currentAppName = appName)
65154

66-
export const toggleExpandAllActions: Action = ({ mutate }) =>
67-
mutate(mutations.toggleExpandAllActions)
155+
export const toggleExpandAllActions: Action = ({ state }) =>
156+
(state.expandAllActionDetails = !state.expandAllActionDetails)

0 commit comments

Comments
 (0)