alien-signals
Advanced tools
Comparing version
{ | ||
"name": "alien-signals", | ||
"version": "1.1.0-alpha.3", | ||
"version": "2.0.0-alpha.0", | ||
"sideEffects": false, | ||
@@ -5,0 +5,0 @@ "license": "MIT", |
@@ -24,34 +24,37 @@ export interface Dependency { | ||
Tracking = 4, | ||
Notified = 8, | ||
Recursed = 16, | ||
Dirty = 32, | ||
PendingComputed = 64, | ||
PendingEffect = 128, | ||
Cold = 256, | ||
Propagated = 224 | ||
Recursed = 8, | ||
Dirty = 16, | ||
Pending = 32, | ||
Cold = 64, | ||
Propagated = 48 | ||
} | ||
export declare function createReactiveSystem({ updateComputed, notifyEffect, }: { | ||
/** | ||
* Updates the computed subscriber's value and returns whether it changed. | ||
* | ||
* This function should be called when a computed subscriber is marked as Dirty. | ||
* The computed subscriber's getter function is invoked, and its value is updated. | ||
* If the value changes, the new value is stored, and the function returns `true`. | ||
* | ||
* @param computed - The computed subscriber to update. | ||
* @returns `true` if the computed subscriber's value changed; otherwise `false`. | ||
*/ | ||
updateComputed(computed: Dependency & Subscriber): boolean; | ||
/** | ||
* Handles effect notifications by processing the specified `effect`. | ||
* | ||
* When an `effect` first receives any of the following flags: | ||
* - `Dirty` | ||
* - `PendingComputed` | ||
* - `PendingEffect` | ||
* this method will process them and return `true` if the flags are successfully handled. | ||
* If not fully handled, future changes to these flags will trigger additional calls | ||
* until the method eventually returns `true`. | ||
*/ | ||
notifyEffect(effect: Subscriber): boolean; | ||
export declare function createReactiveSystem({ computed: { update: updateComputed, onUnwatched: onUnwatchedComputed, }, effect: { notify: notifyEffect, }, }: { | ||
computed: { | ||
/** | ||
* Updates the computed subscriber's value and returns whether it changed. | ||
* | ||
* This function should be called when a computed subscriber is marked as Dirty. | ||
* The computed subscriber's getter function is invoked, and its value is updated. | ||
* If the value changes, the new value is stored, and the function returns `true`. | ||
* | ||
* @param computed - The computed subscriber to update. | ||
* @returns `true` if the computed subscriber's value changed; otherwise `false`. | ||
*/ | ||
update(computed: Dependency & Subscriber): boolean; | ||
onUnwatched?: (computed: Dependency & Subscriber) => void; | ||
}; | ||
effect: { | ||
/** | ||
* Handles effect notifications by processing the specified `effect`. | ||
* | ||
* When an `effect` first receives any of the following flags: | ||
* - `Dirty` | ||
* - `PendingComputed` | ||
* - `PendingEffect` | ||
* this method will process them and return `true` if the flags are successfully handled. | ||
* If not fully handled, future changes to these flags will trigger additional calls | ||
* until the method eventually returns `true`. | ||
*/ | ||
notify(effect: Subscriber): void; | ||
}; | ||
}): { | ||
@@ -95,24 +98,13 @@ /** | ||
/** | ||
* Updates the dirty flag for the given subscriber based on its dependencies. | ||
* Recursively checks and updates all computed subscribers marked as pending. | ||
* | ||
* If the subscriber has any pending computeds, this function sets the Dirty flag | ||
* and returns `true`. Otherwise, it clears the PendingComputed flag and returns `false`. | ||
* It traverses the linked structure using a stack mechanism. For each computed | ||
* subscriber in a pending state, updateComputed is called and shallowPropagate | ||
* is triggered if a value changes. Returns whether any updates occurred. | ||
* | ||
* @param sub - The subscriber to update. | ||
* @param flags - The current flag set for this subscriber. | ||
* @returns `true` if the subscriber is marked as Dirty; otherwise `false`. | ||
* @param link - The starting link representing a sequence of pending computeds. | ||
* @returns `true` if a computed was updated, otherwise `false`. | ||
*/ | ||
updateDirtyFlag(sub: Subscriber, flags: SubscriberFlags): boolean; | ||
checkDirty(link: Link): boolean; | ||
/** | ||
* Updates the computed subscriber if necessary before its value is accessed. | ||
* | ||
* If the subscriber is marked Dirty or PendingComputed, this function runs | ||
* the provided updateComputed logic and triggers a shallowPropagate for any | ||
* downstream subscribers if an actual update occurs. | ||
* | ||
* @param computed - The computed subscriber to update. | ||
* @param flags - The current flag set for this subscriber. | ||
*/ | ||
processComputedUpdate(computed: Dependency & Subscriber, flags: SubscriberFlags): void; | ||
/** | ||
* Ensures all pending internal effects for the given subscriber are processed. | ||
@@ -128,3 +120,3 @@ * | ||
*/ | ||
processPendingInnerEffects(sub: Subscriber, flags: SubscriberFlags): void; | ||
processPendingInnerEffects(sub: Subscriber): void; | ||
/** | ||
@@ -138,2 +130,4 @@ * Processes queued effect notifications after a batch operation finishes. | ||
processEffectNotifications(): void; | ||
warming: (sub: Subscriber & Dependency) => void; | ||
cooling: (sub: Subscriber & Dependency) => void; | ||
}; |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
56467
-3.98%1517
-1.81%