파이버
파이버는 로드된 플러그인 인스턴스 하나로, 수명 주기 상태, 검증된 config, 등록된 effect를 포함합니다. ctx.fiber는 현재 파이버이며, ctx.effect()는 이를 위임합니다.
ctx.effect(execute, label?)
/**
* Register a cleanup-aware effect on this fiber.
*
* `execute` runs immediately; the disposers it produces are collected and
* run (in reverse order) either when the returned disposer is called or
* when the fiber unloads, whichever comes first. Calling the disposer twice
* is a no-op. Throws `CordisError('INACTIVE_EFFECT')` if the fiber is
* already disposed, and `TypeError` if `execute` returns an invalid shape.
*
* @param execute — the effect body; see {@link Effect} for accepted shapes.
* @param label — effect label shown in `getEffects()` diagnostics.
* @returns a disposer that tears the effect down and settles once done.
*/
effect(execute: () => SyncEffect, label?: string): Disposable<Promise<void>>
effect(execute: () => Effect, label?: string): AsyncDisposable<Promise<void>>이 파이버에 정리 작업을 인식하는 effect를 등록합니다.
execute는 즉시 실행됩니다. 생성한 disposer는 수집되며, 반환된 disposer가 호출되거나 파이버가 언로드될 때 중 먼저 발생하는 시점에 역순으로 실행됩니다. disposer를 두 번 호출해도 아무 작업도 수행하지 않습니다. 파이버가 이미 폐기된 경우 CordisError('INACTIVE_EFFECT')를 throw하고, execute가 잘못된 형태를 반환하면 TypeError를 throw합니다.
execute— effect 본문입니다. 허용되는 형태는Effect를 참조하세요.label—getEffects()진단에 표시되는 effect 레이블입니다.
반환값 effect를 해제하고 완료되면 이행되는 disposer를 반환합니다.
ctx.fiber
/** The fiber (plugin runtime instance) that owns this context. */
fiber: Fiber이 컨텍스트를 소유하는 파이버(플러그인 런타임 인스턴스)입니다.
Fiber 클래스
플러그인 애플리케이션 하나의 런타임 인스턴스입니다.
파이버는 ctx.plugin()가 반환하는 플러그인 컨텍스트의 의존성 상태, 검증된 config, 수명 주기 effect 및 정리 작업을 추적합니다.
fiber.uid
/** Unique id within the registry; 0 for the root fiber, `null` once disposed. */
public uid: number | null레지스트리 내 고유 id입니다. 루트 파이버의 경우 0이며, 폐기되면 null입니다.
fiber.ctx
/** The context this fiber's plugin runs in (extends the parent context). */
public readonly ctx: Context이 파이버의 플러그인이 실행되는 컨텍스트입니다(부모 컨텍스트를 확장함).
fiber.config
/** The validated plugin config (updated by `update()`). */
public config: any검증된 플러그인 config입니다(update()로 업데이트됨).
fiber.state
/** Current lifecycle state; transitions emit `internal/status`. */
public state현재 수명 주기 상태입니다. 전환 시 internal/status를 emit합니다.
fiber.dispose
/** Dispose this fiber: unload the plugin, then settle once cleanup finished. */
public readonly dispose: () => Promise<void>이 파이버를 폐기합니다. 플러그인을 언로드한 후 정리 작업이 완료되면 이행됩니다.
fiber.store
/** Snapshot of required service implementations while loaded; `undefined` otherwise. */
public store: Dict<Impl> | undefined로드된 동안 필요한 서비스 구현의 스냅샷이며, 그 외에는 undefined입니다.
fiber.inertia
/** The in-flight load/unload transition, if one is currently running. */
public inertia: Promise<void> | undefined현재 실행 중인 로드/언로드 전환입니다(있는 경우).
fiber.name
/** The plugin's display name, inherited from the nearest named ancestor, else `'root'`. */
get name()플러그인의 표시 이름입니다. 가장 가까운 이름이 지정된 상위 요소에서 상속하며, 없으면 'root'입니다.
fiber.assertActive()
/**
* Throw if the fiber has already been disposed.
*
* @returns nothing when the fiber is still active.
* @throws {CordisError} `INACTIVE_EFFECT` when the fiber's uid has been cleared.
*/
assertActive()파이버가 이미 폐기된 경우 throw합니다.
반환값 파이버가 아직 활성 상태이면 아무것도 반환하지 않습니다.
fiber.effect(execute, label?)
/**
* Register a cleanup-aware effect on this fiber.
*
* `execute` runs immediately; the disposers it produces are collected and
* run (in reverse order) either when the returned disposer is called or
* when the fiber unloads, whichever comes first. Calling the disposer twice
* is a no-op. Throws `CordisError('INACTIVE_EFFECT')` if the fiber is
* already disposed, and `TypeError` if `execute` returns an invalid shape.
*
* @param execute — the effect body; see {@link Effect} for accepted shapes.
* @param label — effect label shown in `getEffects()` diagnostics.
* @returns a disposer that tears the effect down and settles once done.
*/
effect(execute: () => SyncEffect, label?: string): Disposable<Promise<void>>
effect(execute: () => Effect, label?: string): AsyncDisposable<Promise<void>>이 파이버에 정리 작업을 인식하는 effect를 등록합니다.
execute는 즉시 실행됩니다. 생성한 disposer는 수집되며, 반환된 disposer가 호출되거나 파이버가 언로드될 때 중 먼저 발생하는 시점에 역순으로 실행됩니다. disposer를 두 번 호출해도 아무 작업도 수행하지 않습니다. 파이버가 이미 폐기된 경우 CordisError('INACTIVE_EFFECT')를 throw하고, execute가 잘못된 형태를 반환하면 TypeError를 throw합니다.
execute— effect 본문입니다. 허용되는 형태는Effect를 참조하세요.label—getEffects()진단에 표시되는 effect 레이블입니다.
반환값 effect를 해제하고 완료되면 이행되는 disposer를 반환합니다.
fiber.getEffects()
/**
* Return metadata for currently registered effects.
*
* @returns one {@link EffectMeta} tree per labeled live effect.
*/
getEffects()현재 등록된 effect의 메타데이터를 반환합니다.
반환값 레이블이 있는 활성 effect마다 EffectMeta 트리 하나를 반환합니다.
fiber.await()
/**
* Wait for current lifecycle work and rethrow startup errors.
*
* @returns this fiber, once it has settled into a stable state.
* @throws the config-validation or plugin-startup error, if any.
*/
async await()현재 수명 주기 작업을 기다리고 시작 오류를 다시 throw합니다.
반환값 안정된 상태로 이행된 이 파이버를 반환합니다.
fiber.restart()
/**
* Dispose and immediately reload this plugin with its current config.
*
* @returns a promise resolving once the reload settled.
* @throws {CordisError} `INACTIVE_EFFECT` when the fiber is already disposed.
*/
async restart()이 플러그인을 폐기하고 현재 config로 즉시 다시 로드합니다.
반환값 다시 로드가 완료되면 이행되는 promise를 반환합니다.
fiber.update(config, noSave?)
/**
* Validate and apply new config, then restart the plugin.
*
* Runs the `internal/update` waterfall first, so update hooks (and HMR)
* can veto or replace the restart.
*
* @param config — the new raw config; validated before anything restarts.
* @param noSave — hint for persistence hooks not to write the change back.
* @returns the update waterfall result; the default restart returns a promise.
* @throws when validation, an update listener, or the restarted plugin fails.
*/
update(config: any, noSave = false)새 설정을 검증하고 적용한 다음 플러그인을 다시 시작합니다.
먼저 internal/update 워터폴을 실행하므로 업데이트 훅(및 HMR)이 재시작을 거부하거나 대체할 수 있습니다.
config— 새 원시 설정이며, 무엇이든 다시 시작하기 전에 검증됩니다.noSave— 영속성 훅이 변경 사항을 다시 기록하지 않도록 하는 힌트입니다.
업데이트 워터폴 결과를 반환합니다 . 기본 재시작은 promise를 반환합니다.
이펙트
ctx.effect() 및 플러그인 시작에서 허용하는 이펙트 본문 결과입니다.
단일 disposer, disposer를 반환하는 promise 또는 여러 disposer를 생성하는 (비동기일 수 있는) iterable입니다. 제너레이터 이펙트는 생성되는 각 disposer를 등록합니다.
/**
* Effect body result accepted by `ctx.effect()` and plugin startup.
*
* Either a single disposer, a promise of one, or a (possibly async) iterable
* yielding several — generator effects register each yielded disposer as it
* is produced.
*/
type Effect<T = any> =
| SyncEffect<T>
| AsyncEffect<T>해제 함수
해제 시 리소스를 해제하기 위해 이펙트가 반환하는 함수입니다.
소유 fiber가 언로드될 때 disposer는 등록된 역순으로 실행됩니다. 비동기일 수 있으며, 이 경우 언로드는 완료를 기다립니다.
/**
* Function returned by an effect to release resources during disposal.
*
* Disposers run in reverse registration order when the owning fiber unloads;
* they may be async, in which case unloading awaits them.
*/
type Disposable<T = any> = () => TEffectMeta
진단을 위해 중첩된 이펙트 레이블을 노출하는 트리 노드입니다.
/** Tree node used to expose nested effect labels for diagnostics. */
interface EffectMeta {
/** Human-readable effect label, e.g. `ctx.on("event")` or `ctx.provide("name")`. */
label: string
/** Metadata of nested effects registered while this effect ran. */
children: EffectMeta[]
}CordisError
안정적인 기계 판독 가능 코드를 갖는 프레임워크 오류입니다.
/** Framework error with a stable machine-readable code. */
class CordisError extends Error {
/**
* @param code — the stable error code; also the default message.
* @param message — optional human-readable override.
*/
constructor(public code: CordisError.Code, message?: string)
}
/** Cordis error code definitions. */
namespace CordisError {
export type Code = keyof typeof Code
export const Code = {
INACTIVE_EFFECT: 'cannot create effect on inactive context',
} as const
}ValidationError
플러그인 설정이 standard-schema 검증에 실패할 때 발생하는 오류입니다.
/** Error raised when plugin configuration fails standard-schema validation. */
class ValidationError extends TypeError {
name = 'ValidationError'
/**
* Build the aggregated message from schema issues.
*
* @param issues — the standard-schema issues, one message line each.
*/
constructor(issues: readonly StandardSchemaV1.Issue[])
}