-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #5 from nihil-pro/synchronous-transactions
Synchronous transactions
- Loading branch information
Showing
12 changed files
with
745 additions
and
564 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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.