mirror of
https://github.com/toeverything/AFFiNE.git
synced 2026-02-16 22:07:09 +08:00
feat(core): add doc grant feature to share menu (#9672)
This commit is contained in:
@@ -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;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user