Skip to content
This repository was archived by the owner on Apr 30, 2026. It is now read-only.

Commit b2d957f

Browse files
committed
Update type for stores
1 parent 97570db commit b2d957f

3 files changed

Lines changed: 23 additions & 11 deletions

File tree

src/js/stores/AppStore.tsx

Lines changed: 11 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -3,11 +3,16 @@ import { encodeSource, decodeSource, getHosts, setHosts } from 'libs'
33
import isEqual from 'lodash.isequal'
44
import sizeof from 'object-sizeof'
55
import { js } from 'js-beautify'
6+
import Store from 'stores'
7+
8+
type Host = { isRegex: boolean; pattern: string } | string
69

710
const key = 'popup'
811
const defaultSource = '// Here You can type your custom JavaScript...'
912

1013
export default class AppStore {
14+
store: Store
15+
1116
constructor (store) {
1217
this.store = store
1318
}
@@ -20,7 +25,7 @@ export default class AppStore {
2025

2126
@observable saved = false
2227

23-
@observable hosts = []
28+
@observable hosts: Host[] = []
2429

2530
@observable enable = false
2631

@@ -36,7 +41,7 @@ export default class AppStore {
3641

3742
@observable protocol = ''
3843

39-
@observable matchedHost = ''
44+
@observable matchedHost: Host = ''
4045

4146
@observable loadError = null
4247

@@ -61,17 +66,12 @@ export default class AppStore {
6166

6267
@computed
6368
get target () {
64-
if (this.isRegex) {
69+
if (typeof this.matchedHost === 'object' && this.matchedHost.isRegex) {
6570
return this.matchedHost.pattern
6671
}
6772
return this.domain
6873
}
6974

70-
@computed
71-
get isRegex () {
72-
return this.matchedHost && this.matchedHost.isRegex
73-
}
74-
7575
@computed
7676
get differentURL () {
7777
return !this.tab.url.startsWith(this.domain)
@@ -101,7 +101,7 @@ export default class AppStore {
101101

102102
@computed
103103
get domainKey () {
104-
if (this.isRegex) {
104+
if (typeof this.matchedHost === 'object' && this.matchedHost.isRegex) {
105105
return `${key}-${this.matchedHost.pattern}`
106106
}
107107
return `${key}-${this.domain}`
@@ -257,8 +257,9 @@ export default class AppStore {
257257
newHosts = this.hosts.filter(x => x !== this.domain)
258258
} else {
259259
Object.assign(message, this.matchedHost)
260+
const { pattern } = this.matchedHost
260261
newHosts = this.hosts.filter(
261-
x => !x.isRegex || x.pattern !== this.matchedHost.pattern
262+
x => typeof x === 'string' || (!x.isRegex || x.pattern !== pattern)
262263
)
263264
}
264265
this.saveHosts(newHosts)

src/js/stores/IncludeStore.tsx

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,14 @@
11
import { action, computed, observable } from 'mobx'
2+
import Store from 'stores'
23

34
const hint =
45
'# Uncomment address of script below or type your own (one per line and must end with ;)'
56
const underscore =
67
'# //cdnjs.cloudflare.com/ajax/libs/underscore.js/1.8.3/underscore-min.js;'
78

89
export default class IncludeStore {
10+
store: Store
11+
912
constructor (store) {
1013
this.store = store
1114
}

src/js/stores/NewPatternStore.tsx

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,10 @@
11
import { action, computed, observable } from 'mobx'
2+
import Store from 'stores'
23

34
export default class NewPatternStore {
5+
store: Store
6+
re: RegExp
7+
48
constructor (store) {
59
this.store = store
610
}
@@ -33,7 +37,11 @@ export default class NewPatternStore {
3337
return err.message
3438
}
3539
const { hosts } = this.store.AppStore
36-
if (hosts.find(x => x.isRegex && x.pattern === this.pattern)) {
40+
if (
41+
hosts.find(
42+
x => typeof x === 'object' && (x.isRegex && x.pattern === this.pattern)
43+
)
44+
) {
3745
return `Pattern ${this.pattern} already exists`
3846
}
3947
}

0 commit comments

Comments
 (0)