feat(core): appstate
This commit is contained in:
@@ -1,14 +1,48 @@
|
||||
const std = @import("std");
|
||||
const models = @import("../core/models.zig");
|
||||
const Tab = @import("../core/tab/tab.zig").Tab;
|
||||
const locked = @import("../core/sync.zig").locked;
|
||||
|
||||
running: bool = true,
|
||||
usage_number: locked(u16) = .{ .data = 0 },
|
||||
current_items: locked(?[]*models.Item) = .{ .data = null },
|
||||
current_items_allocator: std.heap.ArenaAllocator,
|
||||
tab: *Tab,
|
||||
appState: AppState,
|
||||
_private: Private,
|
||||
|
||||
const Private = struct {
|
||||
preCurrentItemsUnload: Observer(*Tab),
|
||||
};
|
||||
|
||||
pub fn init(model: *Self, currentItemsAllocator: std.heap.ArenaAllocator, appState: AppState) !void {
|
||||
model.* = Self{
|
||||
.current_items_allocator = currentItemsAllocator,
|
||||
.appState = appState,
|
||||
._private = .{
|
||||
.preCurrentItemsUnload = Observer(*Tab){
|
||||
.ctx = @ptrCast(@alignCast(model)),
|
||||
.update = preCurrentItemsUnload,
|
||||
},
|
||||
},
|
||||
};
|
||||
|
||||
try model.appState.tabPreCurrentItemsUnload.attach(&model._private.preCurrentItemsUnload);
|
||||
}
|
||||
|
||||
pub fn preCurrentItemsUnload(ctx: *anyopaque, tab: *Tab) void {
|
||||
const self: *Self = @ptrCast(@alignCast(ctx));
|
||||
if (tab == self.appState.currentTab) {
|
||||
// @panic("asdasdasd");
|
||||
self.current_items.mutex.lock();
|
||||
defer self.current_items.mutex.unlock();
|
||||
|
||||
self.current_items.data = null;
|
||||
}
|
||||
}
|
||||
|
||||
pub fn deinit(self: *@This()) void {
|
||||
self.current_items_allocator.deinit();
|
||||
}
|
||||
|
||||
const std = @import("std");
|
||||
const models = @import("../core/models.zig");
|
||||
const Tab = @import("../core/tab/tab.zig").Tab;
|
||||
const locked = @import("../core/sync.zig").locked;
|
||||
const AppState = @import("../core/app_state.zig").AppState;
|
||||
const Observer = @import("../core/observable.zig").Observer;
|
||||
const Self = @This();
|
||||
|
||||
Reference in New Issue
Block a user