Skip to content

Commit

Permalink
Merge pull request #738 from hyoo-ru/view-custom-promise
Browse files Browse the repository at this point in the history
$mol_promise_blocker added custom promise
  • Loading branch information
zerkalica authored Feb 10, 2025
2 parents 25933e4 + 989419c commit 37bc614
Show file tree
Hide file tree
Showing 5 changed files with 42 additions and 19 deletions.
11 changes: 10 additions & 1 deletion book2/catalog/catalog.view.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,13 @@ namespace $.$$ {
*/
export class $mol_book2_catalog extends $.$mol_book2_catalog {

spread_current() {
return this.spread() === '' ? this.Spread_default() : this.Spread(this.spread())
}

@ $mol_mem
pages() {
const spread = this.spread() === '' ? this.Spread_default() : this.Spread(this.spread())
const spread = this.spread_current()
return [
this.Menu(),
... spread
Expand All @@ -19,6 +23,11 @@ namespace $.$$ {
]
}

override auto() {
const spread = this.spread_current()
if (spread instanceof $mol_book2) spread.auto()
}

@ $mol_mem
override spread_ids(): readonly string[] {
return Object.keys( this.spreads() )
Expand Down
7 changes: 7 additions & 0 deletions promise/blocker/blocker.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
namespace $ {

export class $mol_promise_blocker<Result> extends $mol_promise<Result> {
static [Symbol.toStringTag] = '$mol_promise_blocker'
}

}
37 changes: 22 additions & 15 deletions promise/promise/promise.ts
Original file line number Diff line number Diff line change
@@ -1,20 +1,27 @@
namespace $ {
export class $mol_promise<Result = void> extends Promise<Result> {
done: (value: Result | PromiseLike<Result>) => void
fail: (reason?: any) => void

constructor(
executor?: (
done: (value: Result | PromiseLike<Result>) => void,
fail: (reason?: any) => void
) => void
) {
let done: (value: Result | PromiseLike<Result>) => void
let fail: (reason?: any) => void

super((d, f) => {
done = d
fail = f
executor?.(d, f)
})

this.done = done!
this.fail = fail!
}

export function $mol_promise< Result = void >() {

let done!: ( res: Result | PromiseLike< Result > )=> void
let fail!: ( error?: any ) => void

const promise = new Promise< Result >( ( d, f ) => {
done = d
fail = f
} )

return Object.assign( promise, {
done,
fail,
} )

}

}
4 changes: 2 additions & 2 deletions view/view/view.css
Original file line number Diff line number Diff line change
Expand Up @@ -58,8 +58,7 @@
height: auto;
}
}

[mol_view][mol_view_error]:not([mol_view_error="Promise"]) {
[mol_view][mol_view_error]:not([mol_view_error="Promise"], [mol_view_error="$mol_promise_blocker"]) {
background-image: repeating-linear-gradient(
-45deg,
#f92323,
Expand All @@ -84,6 +83,7 @@
}
}

:where([mol_view][mol_view_error="$mol_promise_blocker"]),
:where([mol_view][mol_view_error="Promise"]) {
background: var(--mol_theme_hover);
}
Expand Down
2 changes: 1 addition & 1 deletion wait/timeout/timeout.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
namespace $ {

export function $mol_wait_timeout_async( this: $, timeout: number ): Promise< void > {
const promise = $mol_promise()
const promise = new $mol_promise()
const task = new this.$mol_after_timeout( timeout , ()=> promise.done() )
return Object.assign( promise, {
destructor: ()=> task.destructor()
Expand Down

0 comments on commit 37bc614

Please sign in to comment.