Si no has oído hablar de él antes, Effect^ es una potente biblioteca TypeScript diseñada para ayudar a los desarrolladores a crear fácilmente programas complejos, sincronizados y asincrónicos.
StudioCMS utiliza Effect para gestionar la mayor parte de nuestro código, aportando simplicidad y facilidad de reutilización de funciones. También nos ha ayudado a optimizar los tiempos de carga del panel de control mediante un enfoque completamente nuevo al código asincrónico.
Mientras trabajas con StudioCMS y Effect, en lugar de necesitar instalarlo por tu cuenta, StudioCMS proporciona las herramientas Effect mediante la siguiente exportación
example.ts
import{
importEffect
@since ― 2.0.0
@since ― 2.0.0
@since ― 2.0.0
Effect,
importContext
@since ― 2.0.0
@since ― 2.0.0
Context,
importSchema
Schema,
importData
Data}from'studiocms/effect';
Incluye todas las exportaciones base de la exportación por defecto de Effect import {} from 'effect'; así como algunas otras utilidades útiles de effect/Function y personalizadas de StudioCMS.
custom-utils.ts
import{
construnEffect: <A, E>(effect: Effect<A, E, never>) =>Promise<A>
Executes an Effect asynchronously and returns a promise of its result.
@param ― effect - The effect to run.
@returns ― A promise that resolves with the result of the effect.
Generates a logger function that wraps an effectful generator function with logging capabilities.
@param ― label - A string label used to identify the logger.
@returns ―
A function that takes a generator function f and returns an Effect.Effect instance.
The returned function accepts a generator function f that yields wrapped effects (YieldWrap<Effect.Effect>).
It logs the execution of the generator function and its effects using the provided label.
genLogger,
constpipeLogger: ((label: string) => <A, E, R>(effect: Effect<A, E, R>) =>Effect<A, E, R>) & (<A, E, R>(effect: Effect<A, E, R>, label: string) =>Effect<A, E, R>)
Wraps an Effect with additional logging functionality.
This function applies a runtime logger and a log span to the provided Effect,
enabling detailed logging for debugging and monitoring purposes.
@param ― label - A string label used to identify the log entries and span.
@param ― effect - The Effect to be wrapped with logging functionality.
@returns ― A new Effect that includes runtime logging and a log span.
pipeLogger,
construntimeLogger: ((label: string) => <A, E, R>(self: Effect<A, E, R>) =>Effect<A, E, R>) & (<A, E, R>(self: Effect<A, E, R>, label: string) =>Effect<A, E, R>)
Creates a runtime logger effect transformer that applies a specific label to log messages
and configures the logging behavior based on the provided log level.
@param ― label - A string label to associate with the logger for identifying log messages.
@returns ― A higher-order function that takes an Effect and returns a new Effect with
the logger configuration applied.