Skip to content

Commit 5c165ea

Browse files
Merge pull request cerebral#35 from cerebral/devtoolsImprovements
Devtools improvements
2 parents 9b60841 + 517ae38 commit 5c165ea

File tree

47 files changed

+1307
-261
lines changed

Some content is hidden

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

47 files changed

+1307
-261
lines changed

package-lock.json

Lines changed: 5 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: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,8 @@
3131
"styled-components": "3.3.3",
3232
"ws": "5.2.1",
3333
"color": "3.0.0",
34-
"tslib": "1.9.3"
34+
"tslib": "1.9.3",
35+
"color-hash": "1.0.3"
3536
},
3637
"devDependencies": {
3738
"@types/jest": "23.1.4",

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

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,12 @@ import { Todo } from './state'
44
import * as helpers from './helpers'
55
import * as mutations from './mutations'
66

7+
function hasLength(_, value: string) {
8+
return Boolean(value.length)
9+
}
10+
11+
function noop() {}
12+
713
export default (action: Action) => ({
814
changeNewTodoTitle: action<React.ChangeEvent<HTMLInputElement>>()
915
.map(helpers.getEventValue)
Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
1-
export const getEventValue = (_, event: React.ChangeEvent<HTMLInputElement>) =>
2-
event.currentTarget.value
1+
export function getEventValue(_, event: React.ChangeEvent<HTMLInputElement>) {
2+
return Promise.resolve(event.currentTarget.value)
3+
}
34

4-
export const preventEventDefault = (_, event: React.FormEvent) =>
5+
export function preventEventDefault(_, event: React.FormEvent) {
56
event.preventDefault()
7+
}

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

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2,17 +2,22 @@ import { State, Todo } from './state'
22

33
let nextTodoId = 0
44

5-
export const setNewTodoTitle = (state: State, value: string) =>
6-
(state.newTodoTitle = value)
5+
export function setNewTodoTitle(state: State, value: string) {
6+
state.newTodoTitle = value
7+
}
78

8-
export const addTodo = (state: State) =>
9+
export function addTodo(state: State) {
910
state.todos.unshift({
1011
id: String(nextTodoId++),
1112
title: state.newTodoTitle,
1213
completed: false,
1314
})
15+
}
1416

15-
export const clearNewTodoTitle = (state: State) => (state.newTodoTitle = '')
17+
export function clearNewTodoTitle(state: State) {
18+
state.newTodoTitle = ''
19+
}
1620

17-
export const toggleCompleted = (_, todo: Todo) =>
18-
(todo.completed = !todo.completed)
21+
export function toggleCompleted(_, todo: Todo) {
22+
todo.completed = !todo.completed
23+
}

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

Lines changed: 24 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ export class ActionBase<Context, InitialValue, Value = InitialValue> {
3535
this.initialActionId = initialActionId
3636

3737
let currentExecutionId = 0
38-
return Object.assign(function(value) {
38+
const func = Object.assign(function(value) {
3939
const initialOperator = typeof arguments[1] === 'undefined'
4040
const newPath = typeof arguments[2] === 'undefined' ? null : arguments[2]
4141
const executionContext: ExecutionContext = initialOperator
@@ -52,6 +52,8 @@ export class ActionBase<Context, InitialValue, Value = InitialValue> {
5252
actionChain.emit('action:start', {
5353
actionId: executionContext.__execution.actionId,
5454
executionId: executionContext.__execution.executionId,
55+
actionName: func.displayName,
56+
value,
5557
})
5658
}
5759
const returnValue = runOperators
@@ -63,17 +65,21 @@ export class ActionBase<Context, InitialValue, Value = InitialValue> {
6365
actionChain.emit('action:end', {
6466
actionId: executionContext.__execution.actionId,
6567
executionId: executionContext.__execution.executionId,
68+
actionName: func.displayName,
6669
})
6770
})
6871
} else if (initialOperator) {
6972
actionChain.emit('action:end', {
7073
actionId: executionContext.__execution.actionId,
7174
executionId: executionContext.__execution.executionId,
75+
actionName: func.displayName,
7276
})
7377
}
7478

7579
return returnValue
7680
}, this) as any
81+
82+
return func
7783
}
7884
getActionChain = () => {
7985
return this.actionChain
@@ -93,26 +99,34 @@ export class ActionBase<Context, InitialValue, Value = InitialValue> {
9399
? executionContext.__path.concat(newPath)
94100
: executionContext.__path.slice(),
95101
}
96-
const path = executionContextWithPath.__path
97102
const prevResult = this.runOperators
98103
? this.runOperators(props, executionContextWithPath)
99104
: props
100105

101-
const operatorId = ++executionContextWithPath.__execution.operatorId
102-
103106
const produceResult = (currentValue) => {
104107
if (currentValue instanceof StopExecution) {
105108
return currentValue
106109
}
107110

108-
const context = this.actionChain.getContext(executionContextWithPath)
111+
const thisExecution = {
112+
...executionContextWithPath.__execution,
113+
operatorId: executionContextWithPath.__execution.operatorId + 1,
114+
}
115+
116+
executionContextWithPath.__execution.operatorId++
117+
118+
const path = executionContextWithPath.__path
119+
120+
const context = this.actionChain.getContext(
121+
thisExecution,
122+
executionContextWithPath
123+
)
109124

110125
this.actionChain.emit('operator:start', {
111126
type,
112127
name,
113128
path,
114-
...context.__execution,
115-
operatorId,
129+
...thisExecution,
116130
})
117131
const result = cb(context, currentValue)
118132

@@ -122,18 +136,16 @@ export class ActionBase<Context, InitialValue, Value = InitialValue> {
122136
name,
123137
path,
124138
isAsync: true,
125-
...context.__execution,
126-
operatorId,
139+
...thisExecution,
127140
})
128141
return result.then((promiseResult) => {
129142
this.actionChain.emit('operator:end', {
130143
type,
131144
name,
132145
path,
133-
...context.__execution,
146+
...thisExecution,
134147
isAsync: true,
135148
result: promiseResult,
136-
operatorId,
137149
})
138150
return promiseResult
139151
})
@@ -143,10 +155,9 @@ export class ActionBase<Context, InitialValue, Value = InitialValue> {
143155
type,
144156
name,
145157
path,
146-
...context.__execution,
158+
...thisExecution,
147159
isAsync: false,
148160
result: result,
149-
operatorId,
150161
})
151162

152163
return result

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

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -22,9 +22,13 @@ export type Execution = {
2222
export type ActionExecution = {
2323
actionId: number
2424
executionId: number
25+
actionName: string
26+
value?: any
2527
}
2628

27-
export type OperatorExecution = ActionExecution & {
29+
export type OperatorExecution = {
30+
actionId: number
31+
executionId: number
2832
operatorId: number
2933
type: string
3034
name: string
@@ -61,7 +65,7 @@ export class ActionChain<Context> extends EventEmitter<ActionChainEvents> {
6165
this.options.providerExceptions = options.providerExceptions || []
6266
}
6367

64-
getContext(executionContext: ExecutionContext) {
68+
getContext(thisExecution: Execution, executionContext: ExecutionContext) {
6569
const instance = this
6670
const providers = Object.keys(this.context).reduce(
6771
(currentContext, key) => {
@@ -77,15 +81,15 @@ export class ActionChain<Context> extends EventEmitter<ActionChainEvents> {
7781
if (result instanceof Promise) {
7882
result.then((promisedResult) => {
7983
instance.emit('provider', {
80-
...executionContext.__execution,
84+
...thisExecution,
8185
name: key,
8286
method: prop,
8387
result: promisedResult,
8488
})
8589
})
8690
} else {
8791
instance.emit('provider', {
88-
...executionContext.__execution,
92+
...thisExecution,
8993
name: key,
9094
method: prop,
9195
result,

packages/node_modules/action-chain/src/index.test.ts

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -80,6 +80,18 @@ beforeEach(() => {
8080
ActionBase.nextActionId = 0
8181
})
8282

83+
describe('ACTION', () => {
84+
test('should be able to give the action a name', () => {
85+
expect.assertions(1)
86+
const test = action() as any
87+
test.displayName = 'My Name'
88+
actionChain.once('action:start', (execution) => {
89+
expect(execution.actionName).toEqual('My Name')
90+
})
91+
test()
92+
})
93+
})
94+
8395
describe('VALUE', () => {
8496
test('should run and return result', () => {
8597
const test = action<string>()
@@ -91,8 +103,6 @@ describe('VALUE', () => {
91103
describe('CONTEXT', () => {
92104
test('should pass default context', () => {
93105
expect.assertions(2)
94-
const wut = action()
95-
console.log(wut.test)
96106
const test = action().test(({ __execution, __path }: any) => {
97107
expect(__execution).toBeTruthy()
98108
expect(__path).toBeTruthy()
@@ -130,7 +140,7 @@ describe('PROVIDER', () => {
130140
})
131141
fn()
132142
})
133-
test('should track execution of clas instance providers', () => {
143+
test('should track execution of class instance providers', () => {
134144
expect.assertions(2)
135145
const fn = action().test(({ test }) => {
136146
expect(test.foo()).toBe('bar')

packages/node_modules/betsy/package.json

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,5 +33,7 @@
3333
"@types/node": "^10.5.1",
3434
"tslib": "^1.9.3"
3535
},
36-
"devDependencies": {}
36+
"devDependencies": {
37+
"typescript": "^2.9.2"
38+
}
3739
}

packages/node_modules/overmind-devtools/package.json

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,8 @@
99
"overmind-devtools": "bin.js"
1010
},
1111
"scripts": {
12-
"start": "concurrently \"electron ./backend/main\" \"webpack-dev-server --port 3000\"",
13-
"build": "webpack",
12+
"start": "concurrently \"electron ./backend/main\" \"webpack-dev-server --port 3000\"",
13+
"build": "webpack",
1414
"typecheck": "tsc --noEmit",
1515
"test": "jest",
1616
"test:watch": "jest --watch --updateSnapshot --coverage false",
@@ -23,10 +23,11 @@
2323
],
2424
"dependencies": {
2525
"@types/node": "^10.5.1",
26-
"overmind": "next",
2726
"color": "^3.0.0",
27+
"color-hash": "^1.0.3",
2828
"electron": "^2.0.4",
2929
"electron-json-storage": "^4.1.0",
30+
"overmind": "next",
3031
"react": "^16.4.1",
3132
"react-dom": "^16.4.1",
3233
"styled-components": "^3.3.3",

0 commit comments

Comments
 (0)