Bump api@0.0.5 and use the type guard helpers

This commit is contained in:
Paul Frazee 2023-01-02 20:56:35 -06:00
parent f6a0e634d7
commit 6885fb2b41
4 changed files with 22 additions and 40 deletions

View file

@ -4,11 +4,6 @@ import {AtUri} from '../../third-party/uri'
import {RootStoreModel} from './root-store'
import * as apilib from '../lib/api'
interface UnknownPost {
$type: string
[k: string]: unknown
}
function* reactKeyGenerator(): Generator<string> {
let counter = 0
while (true) {
@ -16,17 +11,6 @@ function* reactKeyGenerator(): Generator<string> {
}
}
function isThreadViewPost(
v: GetPostThread.ThreadViewPost | GetPostThread.NotFoundPost | UnknownPost,
): v is GetPostThread.ThreadViewPost {
return v.$type === 'app.bksy.feed.getPostThread#threadViewPost'
}
function isNotFoundPost(
v: GetPostThread.ThreadViewPost | GetPostThread.NotFoundPost | UnknownPost,
): v is GetPostThread.NotFoundPost {
return v.$type === 'app.bsky.feed.getPostThread#notFoundPost'
}
export class PostThreadViewPostModel {
// ui state
_reactKey: string = ''
@ -58,7 +42,7 @@ export class PostThreadViewPostModel {
) {
// parents
if (includeParent && v.parent) {
if (isThreadViewPost(v.parent)) {
if (GetPostThread.isThreadViewPost(v.parent)) {
const parentModel = new PostThreadViewPostModel(
this.rootStore,
keyGen.next().value,
@ -69,7 +53,7 @@ export class PostThreadViewPostModel {
parentModel.assignTreeModels(keyGen, v.parent, true, false)
}
this.parent = parentModel
} else if (isNotFoundPost(v.parent)) {
} else if (GetPostThread.isNotFoundPost(v.parent)) {
this.parent = v.parent
}
}
@ -77,7 +61,7 @@ export class PostThreadViewPostModel {
if (includeChildren && v.replies) {
const replies = []
for (const item of v.replies) {
if (isThreadViewPost(item)) {
if (GetPostThread.isThreadViewPost(item)) {
const itemModel = new PostThreadViewPostModel(
this.rootStore,
keyGen.next().value,
@ -88,7 +72,7 @@ export class PostThreadViewPostModel {
itemModel.assignTreeModels(keyGen, item, false, true)
}
replies.push(itemModel)
} else if (isNotFoundPost(item)) {
} else if (GetPostThread.isNotFoundPost(item)) {
replies.push(item)
}
}