Skip to content

Commit d535a6d

Browse files
chore: Update version to 0.2.2 and refactor state management in main.ts
1 parent 0182c5b commit d535a6d

4 files changed

Lines changed: 20 additions & 22 deletions

File tree

package-lock.json

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

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@ratiosolver/flick",
3-
"version": "0.2.0",
3+
"version": "0.2.2",
44
"type": "module",
55
"description": "A tiny and focused UI framework designed for clarity and speed",
66
"main": "dist/index.js",

playground/main.ts

Lines changed: 16 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -7,57 +7,54 @@ enum Tabs {
77
About,
88
Contact
99
}
10-
let currentTab: Tabs = Tabs.Home;
1110

1211
enum Pages {
1312
Dashboard,
1413
Settings,
1514
Profile,
1615
Help
1716
}
18-
let currentPage: Pages = Pages.Dashboard;
1917

2018
const table_headers = ['ID', 'Name', 'Role'];
2119
const table = [
2220
{ id: 1, name: 'Alice', role: 'Admin' },
2321
{ id: 2, name: 'Bob', role: 'User' },
2422
{ id: 3, name: 'Charlie', role: 'Moderator' }
2523
]
26-
let current_row: number | null = null;
2724

2825
flick.mount(() => {
2926
const navbar = Navbar(OffcanvasBrand('Flick'), NavbarList([
3027
NavbarItem('Home', () => {
31-
currentTab = Tabs.Home;
28+
flick.ctx.currentTab = Tabs.Home;
3229
flick.redraw();
33-
}, currentTab === Tabs.Home),
30+
}, flick.ctx.currentTab === Tabs.Home),
3431
NavbarItem('About', () => {
35-
currentTab = Tabs.About;
32+
flick.ctx.currentTab = Tabs.About;
3633
flick.redraw();
37-
}, currentTab === Tabs.About),
34+
}, flick.ctx.currentTab === Tabs.About),
3835
NavbarItem('Contact', () => {
39-
currentTab = Tabs.Contact;
36+
flick.ctx.currentTab = Tabs.Contact;
4037
flick.redraw();
41-
}, currentTab === Tabs.Contact)
38+
}, flick.ctx.currentTab === Tabs.Contact)
4239
]));
4340

4441
const offcanvas_content = ListGroup([
4542
ListGroupItem('Dashboard', () => {
46-
currentPage = Pages.Dashboard;
43+
flick.ctx.currentPage = Pages.Dashboard;
4744
flick.redraw();
48-
}, currentPage === Pages.Dashboard),
45+
}, flick.ctx.currentPage === Pages.Dashboard),
4946
ListGroupItem('Settings', () => {
50-
currentPage = Pages.Settings;
47+
flick.ctx.currentPage = Pages.Settings;
5148
flick.redraw();
52-
}, currentPage === Pages.Settings),
49+
}, flick.ctx.currentPage === Pages.Settings),
5350
ListGroupItem('Profile', () => {
54-
currentPage = Pages.Profile;
51+
flick.ctx.currentPage = Pages.Profile;
5552
flick.redraw();
56-
}, currentPage === Pages.Profile),
53+
}, flick.ctx.currentPage === Pages.Profile),
5754
ListGroupItem('Help', () => {
58-
currentPage = Pages.Help;
55+
flick.ctx.currentPage = Pages.Help;
5956
flick.redraw();
60-
}, currentPage === Pages.Help),
57+
}, flick.ctx.currentPage === Pages.Help),
6158
ListGroupCheckbox('Enable Notifications', false, (checked) => {
6259
console.log('Notifications toggled:', checked);
6360
}),
@@ -72,9 +69,9 @@ flick.mount(() => {
7269
Button('Click Me', () => console.log('Button clicked!')),
7370
Table(table_headers, table.map(item => Row([item.id.toString(), item.name, item.role], () => {
7471
console.log('Row clicked:', item);
75-
current_row = item.id;
72+
flick.ctx.currentRow = item.id;
7673
flick.redraw();
77-
}, current_row === item.id))),
74+
}, flick.ctx.currentRow === item.id))),
7875
Offcanvas(
7976
OffcanvasBody(offcanvas_content),
8077
OffcanvasHeader('Flick Offcanvas')

src/flick.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ export type Component = () => VNode;
88
class Flick {
99
private old_node: VNode | Element | null = null;
1010
private root: Component | null = null;
11+
public ctx: Record<string | symbol, unknown> = {};
1112

1213
public mount(root: Component = () => App(), container_id: string = 'app') {
1314
this.old_node = document.getElementById(container_id)!;

0 commit comments

Comments
 (0)