mirror of
https://github.com/ragestudio/comty.git
synced 2025-06-10 02:54:15 +00:00
added withEvent
method
This commit is contained in:
parent
ac6e8c9129
commit
c33003b3c6
@ -1,6 +1,7 @@
|
|||||||
import { Extension } from "evite"
|
import { Extension } from "evite"
|
||||||
import store from "store"
|
import store from "store"
|
||||||
import defaultSettings from "schemas/defaultSettings.json"
|
import defaultSettings from "schemas/defaultSettings.json"
|
||||||
|
import { Observable } from "rxjs"
|
||||||
|
|
||||||
export default class SettingsExtension extends Extension {
|
export default class SettingsExtension extends Extension {
|
||||||
constructor(app, main) {
|
constructor(app, main) {
|
||||||
@ -52,6 +53,23 @@ export default class SettingsExtension extends Extension {
|
|||||||
return this.settings[key]
|
return this.settings[key]
|
||||||
}
|
}
|
||||||
|
|
||||||
|
withEvent = (listenEvent, defaultValue) => {
|
||||||
|
let value = defaultValue ?? this.settings[key] ?? false
|
||||||
|
|
||||||
|
const observable = new Observable((subscriber) => {
|
||||||
|
subscriber.next(value)
|
||||||
|
|
||||||
|
window.app.eventBus.on(listenEvent, (to) => {
|
||||||
|
value = to
|
||||||
|
subscriber.next(value)
|
||||||
|
})
|
||||||
|
})
|
||||||
|
|
||||||
|
return observable.subscribe((value) => {
|
||||||
|
return value
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
window = {
|
window = {
|
||||||
"settings": this
|
"settings": this
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user