Skip to content

Commit 5e352fd

Browse files
Merge pull request cerebral#8 from cerebral/componentsTab
Components tab
2 parents fcc6d8d + 32f4579 commit 5e352fd

File tree

31 files changed

+527
-51
lines changed

31 files changed

+527
-51
lines changed

package-lock.json

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

package.json

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -65,11 +65,12 @@
6565
"ts-jest": "23.0.0",
6666
"ts-loader": "4.4.2",
6767
"tslib": "1.9.3",
68-
"typescript": "^2.9.2",
68+
"typescript": "2.9.2",
6969
"typescript-eslint-parser": "^16.0.1",
7070
"webpack": "4.15.1",
7171
"webpack-cli": "3.0.8",
72-
"webpack-dev-server": "^3.1.4"
72+
"webpack-dev-server": "^3.1.4",
73+
"url-loader": "1.0.1"
7374
},
7475
"lint-staged": {
7576
"*.{js,ts,tsx}": [

packages/demos/todomvc/src/app/actions.ts

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,9 @@ export default (action: Action) => ({
1111
addTodo: action<React.FormEvent>()
1212
.do(helpers.preventEventDefault)
1313
.mutation(mutations.addTodo)
14-
.mutation(mutations.clearNewTodoTitle),
14+
.mutation(mutations.clearNewTodoTitle)
15+
.filter((_, { state }) => state.todos.length > 2)
16+
.map(() => Promise.resolve())
17+
.mutation((_, state) => (state.todos[2].title = 'mihihihi')),
1518
toggleCompleted: action<Todo>().mutation(mutations.toggleCompleted),
1619
})

packages/demos/todomvc/src/app/mutations.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,13 @@
11
import { State, Todo } from './state'
22

3+
let nextTodoId = 0
4+
35
export const setNewTodoTitle = (value: string, state: State) =>
46
(state.newTodoTitle = value)
57

68
export const addTodo = (_, state: State) =>
79
state.todos.unshift({
10+
id: String(nextTodoId++),
811
title: state.newTodoTitle,
912
completed: false,
1013
})

packages/demos/todomvc/src/app/state.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
export type Todo = {
2+
id: string
23
title: string
34
completed: boolean
45
}

packages/demos/todomvc/src/components/Todos/index.tsx

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,10 @@ import Todo from '../Todo'
55

66
const Todos: React.SFC<Connect> = ({ appState }) => (
77
<List>
8-
{appState.todos.map((todo) => <Todo key={todo.title} todo={todo} />)}
8+
{appState.todos.map(
9+
(todo, index) =>
10+
console.log('todo ID', todo.id) || <Todo key={todo.id} todo={todo} />
11+
)}
912
</List>
1013
)
1114

packages/node_modules/action-chain/src/ActionBase.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -107,7 +107,7 @@ export function actionBaseFactory<
107107

108108
function produceResult(currentValue) {
109109
if (currentValue instanceof StopExecution) {
110-
return currentValue.value
110+
return currentValue
111111
}
112112

113113
const context = actionChain.getContext(executionContextWithPath)

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

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,8 @@ export default (action: Action) => {
3434

3535
const openConsole = action().mutation(mutations.openConsole)
3636

37+
const openComponents = action().mutation(mutations.openComponents)
38+
3739
const openApp = action<string>()
3840

3941
const toggleExpandState = action<string[]>().mutation(
@@ -47,6 +49,7 @@ export default (action: Action) => {
4749
addPort,
4850
openState,
4951
openConsole,
52+
openComponents,
5053
openApp,
5154
toggleExpandState,
5255
}

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

Lines changed: 57 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,13 @@ export const addNewApp = (_, state: State) =>
2424
port: state.newPortValue,
2525
messages: [],
2626
state: {},
27+
components: {},
28+
flushes: [
29+
{
30+
mutations: [],
31+
components: [],
32+
},
33+
],
2734
})
2835

2936
export const resetNewPortValue = (_, state: State) => (state.newPortValue = '')
@@ -38,6 +45,9 @@ export const openState = (_, state: State) => (state.currentTab = Tab.State)
3845

3946
export const openConsole = (_, state: State) => (state.currentTab = Tab.Console)
4047

48+
export const openComponents = (_, state: State) =>
49+
(state.currentTab = Tab.Components)
50+
4151
export const toggleExpandStatePath = (path: string[], state: State) => {
4252
const pathString = path.join('.')
4353

@@ -47,7 +57,7 @@ export const toggleExpandStatePath = (path: string[], state: State) => {
4757
1
4858
)
4959
} else {
50-
state.expandedStatePaths.push(pathString)
60+
state.expandedStatePaths = state.expandedStatePaths.concat(pathString)
5161
}
5262
}
5363

@@ -57,14 +67,58 @@ export const performMutationsByMessageType = (
5767
) => {
5868
message.message.forEach((clientMessage) => {
5969
switch (clientMessage.type) {
60-
case 'init':
70+
case 'init': {
6171
state.apps[message.port].state = clientMessage.data.state
6272
break
63-
case 'flush':
73+
}
74+
case 'flush': {
75+
state.apps[message.port].flushes.push({
76+
mutations: clientMessage.data.mutations,
77+
components: [],
78+
})
6479
clientMessage.data.mutations.forEach(
6580
runMutation(state.apps[message.port].state)
6681
)
6782
break
83+
}
84+
case 'component:add': {
85+
const id = `${clientMessage.data.componentId}_${
86+
clientMessage.data.componentInstanceId
87+
}`
88+
89+
state.apps[message.port].components[id] = {
90+
id,
91+
isMounted: true,
92+
updateCount: 0,
93+
...clientMessage.data,
94+
}
95+
state.apps[message.port].flushes[
96+
state.apps[message.port].flushes.length - 1
97+
].components.push(id)
98+
break
99+
}
100+
case 'component:update': {
101+
const id = `${clientMessage.data.componentId}_${
102+
clientMessage.data.componentInstanceId
103+
}`
104+
105+
state.apps[message.port].components[id].paths = clientMessage.data.paths
106+
state.apps[message.port].components[id].updateCount++
107+
state.apps[message.port].flushes[
108+
state.apps[message.port].flushes.length - 1
109+
].components.push(id)
110+
break
111+
}
112+
case 'component:remove':
113+
const id = `${clientMessage.data.componentId}_${
114+
clientMessage.data.componentInstanceId
115+
}`
116+
117+
state.apps[message.port].components[id].isMounted = false
118+
state.apps[message.port].flushes[
119+
state.apps[message.port].flushes.length - 1
120+
].components.push(id)
121+
break
68122
}
69123
})
70124
}

packages/node_modules/overmind-devtools/src/client/app/state.ts

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,33 @@
1+
export type Mutation = {
2+
args: any[]
3+
method: string
4+
path: string
5+
}
6+
7+
export type Flush = {
8+
mutations: Mutation[]
9+
components: string[]
10+
}
11+
12+
export type Component = {
13+
id: string
14+
name: string
15+
isMounted: boolean
16+
paths: string[]
17+
updateCount: number
18+
}
19+
20+
export type Components = {
21+
[id: string]: Component
22+
}
23+
124
export type App = {
225
name: string
326
port: string
427
messages: AppMessage[]
528
state: object
29+
components: Components
30+
flushes: Flush[]
631
}
732

833
export type Apps = {
@@ -22,6 +47,7 @@ export type Message = {
2247
export enum Tab {
2348
State = 'State',
2449
Console = 'Console',
50+
Components = 'Components',
2551
}
2652

2753
export type State = {

0 commit comments

Comments
 (0)