Skip to content

Commit 706c125

Browse files
committed
[frontend] use delegates for poptab/pushtab
1 parent dd7418f commit 706c125

File tree

2 files changed

+9
-17
lines changed

2 files changed

+9
-17
lines changed

frontend/src/browser.tsx

Lines changed: 4 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -4,18 +4,12 @@ import { Tabs, Tab } from "./components/TabStrip";
44
import { Omnibox } from "./components/Omnibox";
55
import { scramjet } from "./main";
66
import iconAdd from "@ktibow/iconset-ion/add";
7-
import { popTab, pushTab, Shell } from "./components/Shell";
7+
import { Shell } from "./components/Shell";
88
import { createMenu } from "./components/Menu";
9+
import { createDelegate } from "./delegate";
910

10-
// let a = createState({
11-
// b: createState({
12-
// c: "test",
13-
// }),
14-
// });
15-
// use(a.b.c).listen((v) => {
16-
// console.log("a.b.c changed to", v);
17-
// });
18-
// a.b.c = "test2";
11+
export const pushTab = createDelegate<Tab>();
12+
export const popTab = createDelegate<Tab>();
1913

2014
class StatefulClass {
2115
constructor(state: Stateful<any>) {

frontend/src/components/Shell.tsx

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,13 @@
11
import type { Component } from "dreamland/core";
22
import type { Tab } from "./TabStrip";
33
import { browser } from "../main";
4-
5-
export let pushTab: (tab: Tab) => void;
6-
export let popTab: (tab: Tab) => void;
4+
import { popTab, pushTab } from "../browser";
75

86
export const Shell: Component<{
97
tabs: Tab[];
108
activetab: Tab;
119
}> = function (cx) {
12-
pushTab = (tab) => {
10+
pushTab.listen((tab) => {
1311
tab.frame.frame.classList.add(cx.id);
1412
cx.root.appendChild(
1513
<div
@@ -19,15 +17,15 @@ export const Shell: Component<{
1917
{tab.frame.frame}
2018
</div>
2119
);
22-
};
23-
popTab = (tab) => {
20+
});
21+
popTab.listen((tab) => {
2422
for (let el of cx.root.children) {
2523
if (el.children[0] == tab.frame.frame) {
2624
el.remove();
2725
break;
2826
}
2927
}
30-
};
28+
});
3129

3230
return <div class:unfocus={use(browser.unfocusframes)}></div>;
3331
};

0 commit comments

Comments
 (0)