Chore: inline some 'self'-variables

This commit is contained in:
Pieter Vander Vennet 2024-12-11 02:16:58 +01:00
parent acb651b96f
commit 91a7957b85

View file

@ -1,6 +1,5 @@
import { Utils } from "../Utils" import { Utils } from "../Utils"
import { Readable, Subscriber, Unsubscriber, Updater, Writable } from "svelte/store" import { Readable, Subscriber, Unsubscriber, Updater, Writable } from "svelte/store"
/** /**
* Various static utils * Various static utils
*/ */
@ -952,15 +951,14 @@ export class UIEventSource<T> extends Store<T> implements Writable<T> {
g: (j: J, t: T) => T, g: (j: J, t: T) => T,
allowUnregister = false allowUnregister = false
): UIEventSource<J> { ): UIEventSource<J> {
const self = this
const stack = new Error().stack.split("\n") const stack = new Error().stack.split("\n")
const callee = stack[1] const callee = stack[1]
const newSource = new UIEventSource<J>(f(this.data), "map(" + this.tag + ")@" + callee) const newSource = new UIEventSource<J>(f(this.data), "map(" + this.tag + ")@" + callee)
const update = function () { const update =() => {
newSource.setData(f(self.data)) newSource.setData(f(this.data))
return allowUnregister && newSource._callbacks.length() === 0 return allowUnregister && newSource._callbacks.length() === 0
} }
@ -971,7 +969,7 @@ export class UIEventSource<T> extends Store<T> implements Writable<T> {
if (g !== undefined) { if (g !== undefined) {
newSource.addCallback((latest) => { newSource.addCallback((latest) => {
self.setData(g(latest, self.data)) this.setData(g(latest, this.data))
}) })
} }
@ -980,8 +978,7 @@ export class UIEventSource<T> extends Store<T> implements Writable<T> {
public syncWith(otherSource: UIEventSource<T>, reverseOverride = false): UIEventSource<T> { public syncWith(otherSource: UIEventSource<T>, reverseOverride = false): UIEventSource<T> {
this.addCallback((latest) => otherSource.setData(latest)) this.addCallback((latest) => otherSource.setData(latest))
const self = this otherSource.addCallback((latest) => this.setData(latest))
otherSource.addCallback((latest) => self.setData(latest))
if (reverseOverride) { if (reverseOverride) {
if (otherSource.data !== undefined) { if (otherSource.data !== undefined) {
this.setData(otherSource.data) this.setData(otherSource.data)