mirror of
https://github.com/toeverything/AFFiNE.git
synced 2026-02-25 18:26:05 +08:00
feat(core): add user list service for blocksuite (#10627)
This commit is contained in:
@@ -15,6 +15,7 @@
|
||||
"@affine/env": "workspace:*",
|
||||
"@affine/templates": "workspace:*",
|
||||
"@datastructures-js/binary-search-tree": "^5.3.2",
|
||||
"@preact/signals-core": "^1.8.0",
|
||||
"eventemitter2": "^6.4.9",
|
||||
"foxact": "^0.2.43",
|
||||
"fractional-indexing": "^3.2.0",
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
import { DebugLogger } from '@affine/debug';
|
||||
import { type ReadonlySignal, type Signal, signal } from '@preact/signals-core';
|
||||
import type {
|
||||
InteropObservable,
|
||||
Observer,
|
||||
@@ -140,6 +141,17 @@ export class LiveData<T = unknown>
|
||||
return data$;
|
||||
}
|
||||
|
||||
static fromSignal<T>(signal: ReadonlySignal<T>): LiveData<T> {
|
||||
return LiveData.from(
|
||||
new Observable(subscriber => {
|
||||
signal.subscribe(value => {
|
||||
subscriber.next(value);
|
||||
});
|
||||
}),
|
||||
signal.value
|
||||
);
|
||||
}
|
||||
|
||||
private static GLOBAL_COMPUTED_RECURSIVE_COUNT = 0;
|
||||
|
||||
/**
|
||||
@@ -286,6 +298,19 @@ export class LiveData<T = unknown>
|
||||
this.next(v);
|
||||
}
|
||||
|
||||
private _signal: Signal<T> | undefined;
|
||||
|
||||
get signal(): ReadonlySignal<T> {
|
||||
if (!this._signal) {
|
||||
this._signal = signal(this.value);
|
||||
this.subscribe(v => {
|
||||
// oxlint-disable-next-line no-non-null-assertion
|
||||
this._signal!.value = v;
|
||||
});
|
||||
}
|
||||
return this._signal;
|
||||
}
|
||||
|
||||
next = (v: T) => {
|
||||
if (this.isPoisoned) {
|
||||
throw this.poisonedError;
|
||||
@@ -379,7 +404,6 @@ export class LiveData<T = unknown>
|
||||
);
|
||||
}
|
||||
|
||||
// eslint-disable-next-line rxjs/finnish
|
||||
asObservable(): Observable<T> {
|
||||
return new Observable<T>(subscriber => {
|
||||
return this.subscribe(subscriber);
|
||||
@@ -421,7 +445,7 @@ export class LiveData<T = unknown>
|
||||
override pipe(...args: any[]) {
|
||||
return new Observable(subscriber => {
|
||||
this.ops$.next('watch');
|
||||
// eslint-disable-next-line prefer-spread
|
||||
|
||||
const subscription = this.raw$.pipe
|
||||
.apply(this.raw$, args as any)
|
||||
.subscribe(subscriber);
|
||||
|
||||
Reference in New Issue
Block a user