-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
nihil-pro
authored and
nihil-pro
committed
Dec 15, 2024
1 parent
641e9cf
commit 467b958
Showing
11 changed files
with
735 additions
and
592 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
import { ObservableAdministration } from './Observable.administration.js'; | ||
import { ObservableTransactions } from './Observable.transaction.js'; | ||
|
||
export class ObservableComputed { | ||
#property: string | symbol | ||
#descriptor: PropertyDescriptor | ||
#adm: ObservableAdministration | ||
#proxy: object | ||
enumerable: boolean | undefined | ||
configurable: boolean | undefined | ||
#uncalled = true | ||
#value: any | ||
constructor( | ||
property: string | symbol, | ||
descriptor: PropertyDescriptor, | ||
adm: ObservableAdministration, | ||
proxy: object | ||
) { | ||
this.#property = property | ||
this.#descriptor = descriptor | ||
this.#adm = adm | ||
this.#proxy = proxy | ||
this.configurable = descriptor.configurable | ||
this.enumerable = descriptor.enumerable | ||
} | ||
|
||
get = () => { | ||
this.#adm.batch() | ||
if (this.#uncalled) { | ||
const result = ObservableTransactions.transaction( | ||
() => this.#descriptor.get?.call(this.#proxy), | ||
() => { | ||
const prev = this.#value | ||
this.#value = this.#descriptor.get?.call(this.#proxy) | ||
if (prev !== this.#value) { | ||
this.#adm.report(this.#property, this.#value) | ||
this.#adm.state = 1 | ||
this.#adm.batch() | ||
} | ||
} | ||
) | ||
this.#value = result.result | ||
this.#uncalled = false | ||
return this.#value | ||
} | ||
return this.#value | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.