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