Skip to content

Commit

Permalink
Fix effects tracking via debug(domain) (#246)
Browse files Browse the repository at this point in the history
* fix: debug domain effect tracing

* fix: debug domain add effect log
  • Loading branch information
ilyaagarkov authored Sep 7, 2022
1 parent a072252 commit 3c046f2
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 2 deletions.
16 changes: 16 additions & 0 deletions src/debug/debug.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,7 @@ test('debug domain', async () => {
"[store] domain/_$store 0",
"[event] domain/event 5",
"[store] domain/_$store 5",
"[effect] domain/effect demo",
]
`);

Expand All @@ -122,6 +123,7 @@ test('debug domain', async () => {
"[store] domain/_$store 0",
"[event] domain/event 5",
"[store] domain/_$store 5",
"[effect] domain/effect demo",
"[effect] domain/effect.done {"params":"demo","result":"resultdemo"}",
"[store] domain/_$store 50",
]
Expand Down Expand Up @@ -198,6 +200,12 @@ test('domain is traceable', async () => {
const d = createDomain();
const up = d.createEvent();
const $c = d.createStore(0).on(up, (s) => s + 1);
const fx = d.createEffect(() => {});

sample({
clock: $c,
target: fx
})

debug({ trace: true }, d);

Expand All @@ -214,6 +222,14 @@ test('domain is traceable', async () => {
"<- [store] $c 1",
"<- [$c.on] $c.on(up) 1",
"<- [event] up ",
"[effect] d/fx 1",
"[effect] d/fx trace",
"<- [effect] fx 1",
"<- [sample] 1",
"<- [store] $c 1",
"<- [$c.on] $c.on(up) 1",
"<- [event] up ",
"[effect] d/fx.done {"params":1}",
]
`);
});
Expand Down
10 changes: 8 additions & 2 deletions src/debug/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -212,7 +212,13 @@ function logUnit(unit: Unit<any>, config?: Config) {
logTrace(store);
}
});
unit.onCreateEffect(logEffect);
unit.onCreateEffect(effect => {
log(effect, 'effect');
logEffect(effect);
if (config?.trace) {
logTrace(effect);
}
});
}
}

Expand Down Expand Up @@ -350,7 +356,7 @@ const getGraph = (graph: NodeUnit): Node =>
* This is inlined in the index file because "./scope-cache" import
* does not work correctly with esm imports
* since in the resulting build scope-cache does not have explicit "js" extension
*
*
* TODO: fix this at the level of build configuration
*/
interface Meta {
Expand Down

0 comments on commit 3c046f2

Please sign in to comment.