// A screen's board, read (design note 26203e21): `definitions.board` answers// the person's own row for the screen, or this build's shipped default, and// `BoardSurface` draws whatever came back. Until the answer lands, and when// the call fails, the screen draws the Swift copy of the shipped default// (`BoardDefinition.home/.tools/.database`), so a board is never blank and// never waits on a read to draw its first frame.//// A board row moves with the `.core` family (`InvalidationMap`), so a fold// that names `cotton_board_definitions` reads the board again in place.importCottonKitimportFoundationimportObservation@MainActor@ObservablefinalclassBoardModel: Rereadable {/// The screen's board id: "home", "tools", "database".let id: String/// What the screen draws now: the row the core answered, or this build's own.private(set) var board: BoardDefinitionlet families: Set<ScreenFamily> = [.core] @ObservationIgnored privatelet boards: any BoardsCalling/// The newest read asked: an older answer landing late is dropped. @ObservationIgnored privatevar asking = 0init(boards: any BoardsCalling, id: String) {self.boards = boardsself.id = idself.board = BoardDefinition.shipped(id) }func load() async { asking += 1let asked = askingdo {let answer = tryawait boards.board(id)guard asked == asking else { return }iflet why = answer.passedOver {BoardFeedback.warnOnce("board \(id): the stored board was passed over (\(why)); drawing the shipped one.", key: "row:\(id):\(why)") }guardlet drawn = DefinitionCatalogue.board(answer) else {BoardFeedback.warnOnce("board \(id): the answer held no board this build can read; drawing its own.", key: "unreadable:\(id)")return } board = drawn } catch {// The board this build ships stays drawn: a screen never goes blank// because its layout could not be read.Log.warn("board \(id): the board could not be read (\(error)); drawing this build's own") } }}/// A board pushed over Home (Tools, the database page): the core's answer/// for it, read as it shows and again when a fold names what it draws.@MainActor@ObservablefinalclassPushedBoardParts: Rereadable {private(set) var parts: [BoardEntry] = []let families: Set<ScreenFamily> = [.core] @ObservationIgnored privatelet read: @MainActor () async -> [BoardEntry]?init(read: @escaping @MainActor () async -> [BoardEntry]?) { self.read = read }func load() async {iflet parts = await read() { self.parts = parts } }}/// What a board passed over, said ONCE per launch. A board is drawn on every/// visit; a word per visit would bury the one fact under copies of itself.@MainActorenumBoardFeedback {privatestaticvar said: Set<String> = []/// True the first time `key` is seen in this process, false after.staticfunc firstTime(_ key: String) -> Bool { said.insert(key).inserted }/// A part of a kind this build does not draw: one row in the Feedback/// tool (`definitions.passedOver`, which files at most one per database,/// board and part, ever), asked once per launch.staticfunc passedOver(part: String, board: String, databaseId: String?, databaseName: String?, boards: (any BoardsCalling)?) {guard firstTime("part:\(databaseId ?? "personal"):\(board):\(part)") else { return }Log.warn("board \(board): a part of kind \"\(part)\" is not drawn by this build; passed over.")guardlet boards else { return }Task {do {tryawait boards.passedOver(board: board, part: part, databaseId: databaseId ?? "", databaseName: databaseName ?? "") } catch {Log.warn("board \(board): the passed-over \"\(part)\" could not be filed (\(error))") } } }/// Something about a board read worth one line in the log, once.staticfunc warnOnce(_ message: String, key: String) {guard firstTime(key) else { return }Log.warn(message) }}