Skip to content

Commit 5326e80

Browse files
committed
First working version
1 parent c545b0a commit 5326e80

20 files changed

Lines changed: 473 additions & 569 deletions

dist/hyperapp-devtools.js

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

dist/hyperapp-devtools.js.map

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

dist/src/api.d.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ export interface RuntimeEvent {
3434
level: "info" | "warn" | "error";
3535
}
3636
export declare type PaneDisplay = "fullscreen" | "right" | "bottom";
37-
export declare type ValueDisplay = "state" | "result" | "data";
37+
export declare type ValueDisplay = "state" | "result" | "data" | "debugger-state";
3838
export interface State {
3939
runs: Runs;
4040
logs: RuntimeEvent[];
@@ -52,7 +52,7 @@ export interface Actions {
5252
log(event: RuntimeEvent): any;
5353
logInit(event: InitEvent): any;
5454
logAction(event: ActionEvent): any;
55-
select(state: AppAction | null): any;
55+
select(action: AppAction | null): any;
5656
showPane(shown: boolean): any;
5757
setPaneDisplay(paneDisplay: PaneDisplay): any;
5858
setValueDisplay(valueDisplay: ValueDisplay): any;
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
import "./RunActionItem.scss";
2+
import { State, Actions, AppAction } from "../api";
3+
export interface RunActionItemProps {
4+
state: State;
5+
actions: Actions;
6+
array: AppAction[];
7+
index: number;
8+
action: AppAction;
9+
}
10+
export declare function RunActionItem(props: RunActionItemProps): any;

examples/counter.html

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -25,15 +25,17 @@
2525
}
2626

2727
const actions = {
28-
down: value => state => ({ count: state.count - value }),
29-
up: value => state => ({ count: state.count + value })
28+
// let's have a nested action here, for the sake of the example
29+
add: value => state => ({ count: state.count + value }),
30+
down: () => (_, actions) => actions.add(-1),
31+
up: () => (_, actions) => actions.add(1),
3032
}
3133

3234
function view(state, actions) {
3335
return h("div", { style: { margin: "2rem" } },
3436
h("h1", { style: { margin: "0.5rem" } }, state.count),
35-
h("button", { onclick: () => actions.down(1) }, "-"),
36-
h("button", { onclick: () => actions.up(1) }, "+"),
37+
h("button", { onclick: actions.down }, "-"),
38+
h("button", { onclick: actions.up }, "+"),
3739
)
3840
}
3941

examples/hyperapp-devtools.js

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

package.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,9 +12,9 @@
1212
"typings": "dist/src/index.d.ts",
1313
"scripts": {
1414
"clean": "rimraf dist .rpt2_cache",
15-
"start": "rollup -c -w --serve | cpx dist/hyperapp-devtools.js examples -w",
15+
"start": "rollup -c -w --serve",
1616
"build":
17-
"npm run clean && npm run build:module && npm run build:main && npm run build:min && cpx dist/hyperapp-devtools.js examples",
17+
"npm run clean && npm run build:module && npm run build:main && npm run build:min",
1818
"build:main": "rollup -c && rimraf .rpt2_cache",
1919
"build:min": "rollup -c --min && rimraf .rpt2_cache",
2020
"build:module": "rollup -c --es && rimraf .rpt2_cache"

rollup.config.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ if (options.serve) {
3232
plugins.push(
3333
serve({
3434
open: true,
35-
contentBase: "examples"
35+
contentBase: ["examples", "dist"]
3636
})
3737
)
3838
}

src/actions.ts

Lines changed: 26 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -12,20 +12,28 @@ function mergeResult(state: any, event: api.ActionEvent): any {
1212
return state
1313
}
1414

15+
function isCurrentAction(action: api.AppAction): boolean {
16+
if (action.done) {
17+
return false
18+
}
19+
20+
const length = action.nestedActions.length
21+
return length === 0 || action.nestedActions[length - 1].done
22+
}
23+
1524
/**
1625
* Recursively goes down the tree of actions and append the given event to the last non-done action.
17-
*
1826
*/
19-
function appendAction(
20-
previousAction: api.AppAction,
27+
function appendActionEvent(
28+
action: api.AppAction,
2129
event: api.ActionEvent
2230
): api.AppAction {
23-
if (previousAction.done) {
24-
return previousAction
31+
if (action.done) {
32+
return action
2533
}
2634

2735
// no nested action yet
28-
if (previousAction.nestedActions.length === 0) {
36+
if (isCurrentAction(action)) {
2937
if (!event.callDone) {
3038
// the action calls to a nested action
3139
const nestedAction: api.AppAction = {
@@ -34,41 +42,37 @@ function appendAction(
3442
collapsed: false,
3543
actionData: event.data,
3644
nestedActions: [],
37-
previousState: previousAction.previousState
45+
previousState: action.previousState
3846
}
3947

4048
return {
41-
...previousAction,
49+
...action,
4250
nestedActions: [nestedAction]
4351
}
44-
} else if (previousAction.name === event.action) {
52+
} else if (action.name === event.action) {
4553
// the previous call is now complete: set to done and compute the result
4654
return {
47-
...previousAction,
55+
...action,
4856
done: true,
4957
actionResult: event.result,
50-
nextState: mergeResult(previousAction.previousState, event)
58+
nextState: mergeResult(action.previousState, event)
5159
}
5260
} else {
5361
// error case
54-
console.log(
55-
"Previous action is done and event.callDone",
56-
previousAction,
57-
event
58-
)
62+
console.log("Previous action is done and event.callDone", action, event)
5963
// TODO what to return?!
60-
return previousAction
64+
return action
6165
}
6266
} else {
6367
// there are already some nested actions: call recursivelly
64-
const nested = previousAction.nestedActions
68+
const nested = action.nestedActions
6569
const nestedAction = nested[nested.length - 1]
66-
const newNestedAction = appendAction(nestedAction, event)
70+
const newNestedAction = appendActionEvent(nestedAction, event)
6771
if (nestedAction === newNestedAction) {
68-
return previousAction
72+
return action
6973
}
7074
return {
71-
...previousAction,
75+
...action,
7276
nestedActions: nested.slice(0, nested.length - 1).concat(newNestedAction)
7377
}
7478
}
@@ -125,7 +129,7 @@ export const actions: ActionsType<api.State, api.Actions> = {
125129
}
126130
} else {
127131
// previous action not done: find parent action, create and append
128-
selectedAction = appendAction(prevAction, event)
132+
selectedAction = appendActionEvent(prevAction, event)
129133
actions.push(selectedAction)
130134
}
131135

src/api.ts

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,9 @@ export interface Run {
1515
id: string
1616
timestamp: number
1717
actions: AppAction[]
18+
// // used internally when loging actions
19+
// // each number is the
20+
// currentActionPath: number[]
1821
collapsed: boolean
1922
}
2023

@@ -42,7 +45,7 @@ export interface RuntimeEvent {
4245

4346
export type PaneDisplay = "fullscreen" | "right" | "bottom"
4447

45-
export type ValueDisplay = "state" | "result" | "data"
48+
export type ValueDisplay = "state" | "result" | "data" | "debugger-state"
4649

4750
export interface State {
4851
runs: Runs
@@ -65,7 +68,7 @@ export interface Actions {
6568
log(event: RuntimeEvent)
6669
logInit(event: InitEvent)
6770
logAction(event: ActionEvent)
68-
select(state: AppAction | null)
71+
select(action: AppAction | null)
6972
showPane(shown: boolean)
7073
setPaneDisplay(paneDisplay: PaneDisplay)
7174
setValueDisplay(valueDisplay: ValueDisplay)

0 commit comments

Comments
 (0)