feat: refactor1
This commit is contained in:
@@ -229,10 +229,8 @@ pub fn main() !void {
|
|||||||
defer allocator.free(start_full_name.path);
|
defer allocator.free(start_full_name.path);
|
||||||
|
|
||||||
var tab1 = try allocator.create(Tab);
|
var tab1 = try allocator.create(Tab);
|
||||||
defer allocator.destroy(tab1);
|
|
||||||
|
|
||||||
tab1.init(&pool, &rootProvider, allocator);
|
tab1.init(&pool, &rootProvider, allocator);
|
||||||
defer tab1.deinit();
|
|
||||||
|
|
||||||
try tab1.setCurrentLocation(start_full_name);
|
try tab1.setCurrentLocation(start_full_name);
|
||||||
|
|
||||||
@@ -261,7 +259,8 @@ pub fn main() !void {
|
|||||||
};
|
};
|
||||||
|
|
||||||
var appState: AppState = AppState.init(allocator);
|
var appState: AppState = AppState.init(allocator);
|
||||||
appState.currentTab = tab1;
|
try appState.addTab(tab1);
|
||||||
|
try appState.setCurrentTab(tab1);
|
||||||
|
|
||||||
const model = try allocator.create(Model);
|
const model = try allocator.create(Model);
|
||||||
defer allocator.destroy(model);
|
defer allocator.destroy(model);
|
||||||
|
|||||||
@@ -2,20 +2,20 @@ pub const UnknownTabError = error.UnknownTab;
|
|||||||
|
|
||||||
pub const AppState = struct {
|
pub const AppState = struct {
|
||||||
currentTab: *Tab = undefined,
|
currentTab: *Tab = undefined,
|
||||||
tabs: std.ArrayList(Tab),
|
tabs: std.ArrayList(*Tab),
|
||||||
currentTabChanged: Observable(*Tab),
|
currentTabChanged: Observable(*Tab),
|
||||||
tabPreCurrentItemsUnload: Observable(*Tab),
|
tabPreCurrentItemsUnload: Observable(*Tab),
|
||||||
|
|
||||||
pub fn init(allocator: std.mem.Allocator) AppState {
|
pub fn init(allocator: std.mem.Allocator) AppState {
|
||||||
return .{
|
return .{
|
||||||
.tabs = std.ArrayList(Tab).init(allocator),
|
.tabs = std.ArrayList(*Tab).init(allocator),
|
||||||
.currentTabChanged = Observable(*Tab).init(allocator),
|
.currentTabChanged = Observable(*Tab).init(allocator),
|
||||||
.tabPreCurrentItemsUnload = Observable(*Tab).init(allocator),
|
.tabPreCurrentItemsUnload = Observable(*Tab).init(allocator),
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn addTab(self: *AppState, tab: Tab) void {
|
pub fn addTab(self: *AppState, tab: *Tab) !void {
|
||||||
self.tabs.append(tab);
|
try self.tabs.append(tab);
|
||||||
// tab.preCurrentItemsUnload.attach(.{
|
// tab.preCurrentItemsUnload.attach(.{
|
||||||
// .ctx = @ptrCast(@alignCast(self)),
|
// .ctx = @ptrCast(@alignCast(self)),
|
||||||
// .update = preCurrentItemsUnload,
|
// .update = preCurrentItemsUnload,
|
||||||
@@ -37,7 +37,7 @@ pub const AppState = struct {
|
|||||||
pub fn deinit(self: *AppState) void {
|
pub fn deinit(self: *AppState) void {
|
||||||
self.tabPreCurrentItemsUnload.deinit();
|
self.tabPreCurrentItemsUnload.deinit();
|
||||||
self.currentTabChanged.deinit();
|
self.currentTabChanged.deinit();
|
||||||
for (self.tabs.items) |*tab| {
|
for (self.tabs.items) |tab| {
|
||||||
tab.deinit();
|
tab.deinit();
|
||||||
}
|
}
|
||||||
self.tabs.deinit();
|
self.tabs.deinit();
|
||||||
|
|||||||
@@ -127,6 +127,7 @@ pub const Tab = struct {
|
|||||||
c.item.deinit();
|
c.item.deinit();
|
||||||
}
|
}
|
||||||
self._private.currentItemsAllocator.deinit();
|
self._private.currentItemsAllocator.deinit();
|
||||||
|
self.allocator.destroy(self);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user