Skip to content

Commit

Permalink
refactor(core): mark effect as developer preview again (angular#52490)
Browse files Browse the repository at this point in the history
Re-add the `@developerPreview` flags to `effect()`. While we don't expect
the `effect` API itself to change, we may change how other FW APIs interact
with `effect`s. Also, add a missing export for one of those effect APIs.

PR Close angular#52490
  • Loading branch information
alxhub authored and ChellappanRajan committed Jan 23, 2024
1 parent c48bf6a commit 9865b3e
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 0 deletions.
2 changes: 2 additions & 0 deletions aio/content/guide/signals.md
Expand Up @@ -106,6 +106,8 @@ Effects always run **at least once.** When an effect runs, it tracks any signal

Effects always execute **asynchronously**, during the change detection process.

Note: the `effect()` API is still in [developer preview](/guide/releases#developer-preview) as we work to integrate signal-based reactivity into the core framework.

### Use cases for effects

Effects are rarely needed in most application code, but may be useful in specific circumstances. Here are some examples of situations where an `effect` might be a good solution:
Expand Down
3 changes: 3 additions & 0 deletions goldens/public-api/core/index.md
Expand Up @@ -553,6 +553,9 @@ export function effect(effectFn: (onCleanup: EffectCleanupRegisterFn) => void, o
// @public
export type EffectCleanupFn = () => void;

// @public
export type EffectCleanupRegisterFn = (cleanupFn: EffectCleanupFn) => void;

// @public
export interface EffectRef {
destroy(): void;
Expand Down
1 change: 1 addition & 0 deletions packages/core/src/core_reactivity_export_internal.ts
Expand Up @@ -29,6 +29,7 @@ export {
effect,
EffectRef,
EffectCleanupFn,
EffectCleanupRegisterFn,
EffectScheduler as ɵEffectScheduler,
ZoneAwareQueueingScheduler as ɵZoneAwareQueueingScheduler,
FlushableEffectRunner as ɵFlushableEffectRunner,
Expand Down
10 changes: 10 additions & 0 deletions packages/core/src/render3/reactivity/effect.ts
Expand Up @@ -26,11 +26,15 @@ import {assertNotInReactiveContext} from './asserts';
* An effect can, optionally, register a cleanup function. If registered, the cleanup is executed
* before the next effect run. The cleanup function makes it possible to "cancel" any work that the
* previous effect run might have started.
*
* @developerPreview
*/
export type EffectCleanupFn = () => void;

/**
* A callback passed to the effect function that makes it possible to register cleanup logic.
*
* @developerPreview
*/
export type EffectCleanupRegisterFn = (cleanupFn: EffectCleanupFn) => void;

Expand Down Expand Up @@ -212,6 +216,8 @@ class EffectHandle implements EffectRef, SchedulableEffect {

/**
* A global reactive effect, which can be manually destroyed.
*
* @developerPreview
*/
export interface EffectRef {
/**
Expand All @@ -222,6 +228,8 @@ export interface EffectRef {

/**
* Options passed to the `effect` function.
*
* @developerPreview
*/
export interface CreateEffectOptions {
/**
Expand Down Expand Up @@ -251,6 +259,8 @@ export interface CreateEffectOptions {

/**
* Create a global `Effect` for the given reactive function.
*
* @developerPreview
*/
export function effect(
effectFn: (onCleanup: EffectCleanupRegisterFn) => void,
Expand Down

0 comments on commit 9865b3e

Please sign in to comment.