Skip to content

Commit

Permalink
Merge pull request #346 from POPWorldMedia/typescript5-#345
Browse files Browse the repository at this point in the history
Typescript5 update #345
  • Loading branch information
jeffputz committed Sep 9, 2023
2 parents 0f4a56e + aef17c5 commit 5badf2b
Show file tree
Hide file tree
Showing 18 changed files with 36 additions and 37 deletions.
4 changes: 2 additions & 2 deletions src/PopForums.Mvc/Client/Components/AnswerButton.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
namespace PopForums {

export class AnswerButton extends ElementBase {
export class AnswerButton extends ElementBase<TopicState> {
constructor() {
super();
}
Expand Down Expand Up @@ -46,7 +46,7 @@ namespace PopForums {
super.connectedCallback();
}

getDependentReference(): [StateBase, string] {
getDependentReference(): [TopicState, string] {
return [PopForums.currentTopicState, "answerPostID"];
}

Expand Down
4 changes: 2 additions & 2 deletions src/PopForums.Mvc/Client/Components/CommentButton.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
namespace PopForums {

export class CommentButton extends ElementBase {
export class CommentButton extends ElementBase<TopicState> {
constructor() {
super();
}
Expand Down Expand Up @@ -35,7 +35,7 @@ namespace PopForums {
super.connectedCallback();
}

getDependentReference(): [StateBase, string] {
getDependentReference(): [TopicState, string] {
return [PopForums.currentTopicState, "commentReplyID"];
}

Expand Down
4 changes: 2 additions & 2 deletions src/PopForums.Mvc/Client/Components/FavoriteButton.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
namespace PopForums {

export class FavoriteButton extends ElementBase {
export class FavoriteButton extends ElementBase<TopicState> {
constructor() {
super();
}
Expand Down Expand Up @@ -44,7 +44,7 @@ namespace PopForums {
super.connectedCallback();
}

getDependentReference(): [StateBase, string] {
getDependentReference(): [TopicState, string] {
return [PopForums.currentTopicState, "isFavorite"];
}

Expand Down
4 changes: 2 additions & 2 deletions src/PopForums.Mvc/Client/Components/FullText.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
namespace PopForums {

export class FullText extends ElementBase {
export class FullText extends ElementBase<TopicState> {
constructor() {
super();
}
Expand Down Expand Up @@ -135,7 +135,7 @@ namespace PopForums {
super.connectedCallback();
}

getDependentReference(): [StateBase, string] {
getDependentReference(): [TopicState, string] {
return [PopForums.currentTopicState, "nextQuote"];
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
namespace PopForums {

export class MorePostsBeforeReplyButton extends ElementBase {
export class MorePostsBeforeReplyButton extends ElementBase<TopicState> {
constructor() {
super();
}
Expand All @@ -24,7 +24,7 @@ namespace PopForums {
super.connectedCallback();
}

getDependentReference(): [StateBase, string] {
getDependentReference(): [TopicState, string] {
return [PopForums.currentTopicState, "isNewerPostsAvailable"];
}

Expand Down
4 changes: 2 additions & 2 deletions src/PopForums.Mvc/Client/Components/MorePostsButton.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
namespace PopForums {

export class MorePostsButton extends ElementBase {
export class MorePostsButton extends ElementBase<TopicState> {
constructor() {
super();
}
Expand All @@ -24,7 +24,7 @@ namespace PopForums {
super.connectedCallback();
}

getDependentReference(): [StateBase, string] {
getDependentReference(): [TopicState, string] {
return [PopForums.currentTopicState, "highPage"];
}

Expand Down
4 changes: 2 additions & 2 deletions src/PopForums.Mvc/Client/Components/NotificationList.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
namespace PopForums {

export class NotificationList extends ElementBase {
export class NotificationList extends ElementBase<UserState> {
constructor() {
super();
}
Expand All @@ -9,7 +9,7 @@ namespace PopForums {
super.connectedCallback();
}

getDependentReference(): [StateBase, string] {
getDependentReference(): [UserState, string] {
return [PopForums.userState, "notifications"];
}

Expand Down
4 changes: 2 additions & 2 deletions src/PopForums.Mvc/Client/Components/NotificationToggle.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
namespace PopForums {

export class NotificationToggle extends ElementBase {
export class NotificationToggle extends ElementBase<UserState> {
constructor() {
super();
this.userState = PopForums.userState;
Expand Down Expand Up @@ -47,7 +47,7 @@ namespace PopForums {
this.userState.list.addEventListener("scroll", this.userState.ScrollLoad);
}

getDependentReference(): [StateBase, string] {
getDependentReference(): [UserState, string] {
return [PopForums.userState, "notificationCount"];
}

Expand Down
4 changes: 2 additions & 2 deletions src/PopForums.Mvc/Client/Components/PMCount.ts
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
namespace PopForums {

export class PMCount extends ElementBase {
export class PMCount extends ElementBase<UserState> {
constructor() {
super();
this.isInit = false;
}

private isInit: boolean;

getDependentReference(): [StateBase, string] {
getDependentReference(): [UserState, string] {
return [PopForums.userState, "newPmCount"];
}

Expand Down
4 changes: 2 additions & 2 deletions src/PopForums.Mvc/Client/Components/PreviousPostsButton.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
namespace PopForums {

export class PreviousPostsButton extends ElementBase {
export class PreviousPostsButton extends ElementBase<TopicState> {
constructor() {
super();
}
Expand All @@ -24,7 +24,7 @@ namespace PopForums {
super.connectedCallback();
}

getDependentReference(): [StateBase, string] {
getDependentReference(): [TopicState, string] {
return [PopForums.currentTopicState, "lowPage"];
}

Expand Down
8 changes: 4 additions & 4 deletions src/PopForums.Mvc/Client/Components/QuoteButton.ts
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@
this.onclick = (e: MouseEvent) => {
// get this from topic state's callback/ready method, because iOS loses selection when you touch quote button
let fragment = PopForums.currentTopicState.documentFragment;
let ancestor = PopForums.currentTopicState.selectionAncestor;
let ancestor = PopForums.currentTopicState.selectionAncestor as Element;
if (!fragment) {
let selection = document.getSelection();
if (!selection || selection.rangeCount === 0 || selection.getRangeAt(0).toString().length === 0) {
Expand All @@ -51,16 +51,16 @@
return;
}
let range = selection.getRangeAt(0);
ancestor = range.commonAncestorContainer;
ancestor = range.commonAncestorContainer as Element;
fragment = range.cloneContents();
}
let div = document.createElement("div");
div.appendChild(fragment);
// is selection in the container?
while (ancestor['id'] !== this.containerid && ancestor.parentElement !== null) {
while (ancestor.id !== this.containerid && ancestor.parentElement !== null) {
ancestor = ancestor.parentElement;
}
let isInText = ancestor['id'] === this.containerid;
let isInText = ancestor.id === this.containerid;
// if not, is it partially in the container?
if (!isInText) {
let container = div.querySelector("#" + this.containerid);
Expand Down
4 changes: 2 additions & 2 deletions src/PopForums.Mvc/Client/Components/ReplyButton.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
namespace PopForums {

export class ReplyButton extends ElementBase {
export class ReplyButton extends ElementBase<TopicState> {
constructor() {
super();
}
Expand Down Expand Up @@ -39,7 +39,7 @@ namespace PopForums {
super.connectedCallback();
}

getDependentReference(): [StateBase, string] {
getDependentReference(): [TopicState, string] {
return [PopForums.currentTopicState, "isReplyLoaded"];
}

Expand Down
4 changes: 2 additions & 2 deletions src/PopForums.Mvc/Client/Components/SubscribeButton.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
namespace PopForums {

export class SubscribeButton extends ElementBase {
export class SubscribeButton extends ElementBase<TopicState> {
constructor() {
super();
}
Expand Down Expand Up @@ -44,7 +44,7 @@ namespace PopForums {
super.connectedCallback();
}

getDependentReference(): [StateBase, string] {
getDependentReference(): [TopicState, string] {
return [PopForums.currentTopicState, "isSubscribed"];
}

Expand Down
4 changes: 2 additions & 2 deletions src/PopForums.Mvc/Client/Components/TopicButton.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
namespace PopForums {

export class TopicButton extends ElementBase {
export class TopicButton extends ElementBase<ForumState> {
constructor() {
super();
}
Expand Down Expand Up @@ -29,7 +29,7 @@ namespace PopForums {
super.connectedCallback();
}

getDependentReference(): [StateBase, string] {
getDependentReference(): [ForumState, string] {
return [PopForums.currentForumState, "isNewTopicLoaded"];
}

Expand Down
8 changes: 4 additions & 4 deletions src/PopForums.Mvc/Client/ElementBase.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
namespace PopForums {

export abstract class ElementBase extends HTMLElement {
export abstract class ElementBase<B extends StateBase> extends HTMLElement {

connectedCallback() {
if (this.state && this.propertyToWatch)
Expand All @@ -12,16 +12,16 @@ export abstract class ElementBase extends HTMLElement {
this.state.subscribe(this.propertyToWatch, delegate);
}

private state: StateBase;
private state: B;
private propertyToWatch: string;

update() {
const externalValue = this.state[this.propertyToWatch];
const externalValue = this.state[this.propertyToWatch as keyof B];
this.updateUI(externalValue);
}

// Implementation should return the StateBase and property (as a string) to monitor
abstract getDependentReference(): [StateBase, string];
abstract getDependentReference(): [B, string];

// Use in the implementation to manipulate the shadow or light DOM or straight markup as needed in response to the new data.
abstract updateUI(data: any): void;
Expand Down
1 change: 0 additions & 1 deletion src/PopForums.Mvc/Client/tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@
"outFile": "../wwwroot/PopForums.js",
"experimentalDecorators": true,
"noImplicitAny": true,
"suppressImplicitAnyIndexErrors": true,
"moduleResolution": "Node"
}
}
2 changes: 1 addition & 1 deletion src/PopForums.Mvc/PopForums.Mvc.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@

<ItemGroup>
<FrameworkReference Include="Microsoft.AspNetCore.App" />
<PackageReference Include="Microsoft.TypeScript.MSBuild" Version="4.9.5">
<PackageReference Include="Microsoft.TypeScript.MSBuild" Version="5.2.2">
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
</PackageReference>
Expand Down
2 changes: 1 addition & 1 deletion src/PopForums.Mvc/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
"vue-router": "4.1.6"
},
"devDependencies": {
"typescript": "4.9.5",
"typescript": "5.2.2",
"gulp-typescript": "5.0.1",
"@babel/core": "7.19.3",
"@babel/preset-env": "7.19.3",
Expand Down

0 comments on commit 5badf2b

Please sign in to comment.