Skip to content

Commit a235bc6

Browse files
authored
Merge pull request #51 from ukwhatn/fix/forum-post-source-getter-setter
fix: add source getter/setter to ForumPost for Collection access
2 parents b61dc06 + f954119 commit a235bc6

File tree

1 file changed

+21
-7
lines changed

1 file changed

+21
-7
lines changed

src/module/forum/forum-post.ts

Lines changed: 21 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -63,12 +63,26 @@ export class ForumPost {
6363
return this._parentId;
6464
}
6565

66+
/**
67+
* Get source code (cached)
68+
*/
69+
get source(): string | null {
70+
return this._source;
71+
}
72+
73+
/**
74+
* Set source code
75+
*/
76+
set source(value: string | null) {
77+
this._source = value;
78+
}
79+
6680
/**
6781
* Get source code (Wikidot syntax)
6882
*/
6983
getSource(): WikidotResultAsync<string> {
70-
if (this._source !== null) {
71-
return fromPromise(Promise.resolve(this._source), (e) => new UnexpectedError(String(e)));
84+
if (this.source !== null) {
85+
return fromPromise(Promise.resolve(this.source), (e) => new UnexpectedError(String(e)));
7286
}
7387

7488
return fromPromise(
@@ -77,10 +91,10 @@ export class ForumPost {
7791
if (result.isErr()) {
7892
throw result.error;
7993
}
80-
if (this._source === null) {
94+
if (this.source === null) {
8195
throw new NoElementError('Source textarea not found');
8296
}
83-
return this._source;
97+
return this.source;
8498
})(),
8599
(error) => {
86100
if (error instanceof NoElementError) return error;
@@ -149,7 +163,7 @@ export class ForumPost {
149163
if (title !== undefined) {
150164
this.title = title;
151165
}
152-
this._source = source;
166+
this.source = source;
153167
})(),
154168
(error) => {
155169
if (error instanceof NoElementError || error instanceof LoginRequiredError) {
@@ -502,7 +516,7 @@ export class ForumPostCollection extends Array<ForumPost> {
502516
): WikidotResultAsync<ForumPostCollection> {
503517
return fromPromise(
504518
(async () => {
505-
const targetPosts = posts.filter((post) => post._source === null);
519+
const targetPosts = posts.filter((post) => post.source === null);
506520

507521
if (targetPosts.length === 0) {
508522
return new ForumPostCollection(thread, posts);
@@ -529,7 +543,7 @@ export class ForumPostCollection extends Array<ForumPost> {
529543
if (sourceElem.length === 0) {
530544
throw new NoElementError(`Source textarea not found for post: ${post.id}`);
531545
}
532-
post._source = sourceElem.text();
546+
post.source = sourceElem.text();
533547
}
534548

535549
return new ForumPostCollection(thread, posts);

0 commit comments

Comments
 (0)