feat(editor): replace slot with rxjs subject (#10768)

This commit is contained in:
Mirone
2025-03-12 11:29:24 +09:00
committed by GitHub
parent 19f978d9aa
commit cd63e0ed8b
302 changed files with 1405 additions and 1251 deletions

View File

@@ -1,55 +0,0 @@
import { describe, expect, test, vi } from 'vitest';
import { Slot } from '../slot/slot.js';
describe('slot', () => {
test('init', () => {
const slot = new Slot();
expect(slot).is.toBeDefined();
});
test('emit', () => {
const slot = new Slot<void>();
const callback = vi.fn();
slot.on(callback);
slot.emit();
expect(callback).toBeCalled();
});
test('emit with value', () => {
const slot = new Slot<number>();
const callback = vi.fn(v => expect(v).toBe(5));
slot.on(callback);
slot.emit(5);
expect(callback).toBeCalled();
});
test('listen once', () => {
const slot = new Slot<number>();
const callback = vi.fn(v => expect(v).toBe(5));
slot.once(callback);
slot.emit(5);
slot.emit(6);
expect(callback).toBeCalledTimes(1);
});
test('listen once with dispose', () => {
const slot = new Slot<void>();
const callback = vi.fn(() => {
throw new Error('');
});
const disposable = slot.once(callback);
disposable.dispose();
slot.emit();
expect(callback).toBeCalledTimes(0);
});
test('cycle emit', () => {
const slot = new Slot<number>();
const callback = vi.fn(v => slot.emit(v + 1));
slot.on(callback);
slot.emit(0);
expect(callback).toBeCalledTimes(1);
expect(callback).toBeCalledWith(0);
});
});