feat(core): add doc grant feature to share menu (#9672)

This commit is contained in:
JimmFly
2025-02-07 13:05:58 +00:00
parent 459972fe6c
commit 5ae5fd88f1
57 changed files with 3188 additions and 697 deletions

View File

@@ -1,6 +1,6 @@
import { DebugLogger } from '@affine/debug';
import { Unreachable } from '@affine/env/constant';
import { type OperatorFunction, Subject } from 'rxjs';
import { type OperatorFunction, Subject, type Subscription } from 'rxjs';
const logger = new DebugLogger('effect');
@@ -9,6 +9,8 @@ export type Effect<T> = (T | undefined extends T // hack to detect if T is unkno
: (value: T) => void) & {
// unsubscribe effect, all ongoing effects will be cancelled.
unsubscribe: () => void;
// reset internal state, all ongoing effects will be cancelled.
reset: () => void;
};
/**
@@ -89,36 +91,44 @@ export function effect(...args: any[]) {
}
}
// eslint-disable-next-line prefer-spread
const subscription = subject$.pipe.apply(subject$, args as any).subscribe({
next(value) {
const error = new EffectError('should not emit value', value);
// make a uncaught exception
setTimeout(() => {
throw error;
}, 0);
},
complete() {
const error = new EffectError('effect unexpected complete');
// make a uncaught exception
setTimeout(() => {
throw error;
}, 0);
},
error(error) {
const effectError = new EffectError('effect uncaught error', error);
// make a uncaught exception
setTimeout(() => {
throw effectError;
}, 0);
},
});
let subscription: Subscription | null = null;
function subscribe() {
subscription = subject$.pipe.apply(subject$, args as any).subscribe({
next(value) {
const error = new EffectError('should not emit value', value);
// make a uncaught exception
setTimeout(() => {
throw error;
}, 0);
},
complete() {
const error = new EffectError('effect unexpected complete');
// make a uncaught exception
setTimeout(() => {
throw error;
}, 0);
},
error(error) {
const effectError = new EffectError('effect uncaught error', error);
// make a uncaught exception
setTimeout(() => {
throw effectError;
}, 0);
},
});
}
subscribe();
const fn = (value: unknown) => {
subject$.next(value);
};
fn.unsubscribe = () => subscription.unsubscribe();
fn.unsubscribe = () => subscription?.unsubscribe();
fn.reset = () => {
subscription?.unsubscribe();
subscribe();
};
return fn as never;
}