Skip to content

Commit 9cc808c

Browse files
committed
Update package version to 0.1.16, refactor Reaction class to rename getValue method to computeValue, and add getReactions function to registrar for improved reaction management.
1 parent 48394b6 commit 9cc808c

File tree

6 files changed

+55
-49
lines changed

6 files changed

+55
-49
lines changed

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@flexsurfer/reflex",
3-
"version": "0.1.15",
3+
"version": "0.1.16",
44
"license": "MIT",
55
"repository": {
66
"type": "git",

src/index.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ export { regSub, getSubscriptionValue } from './subs';
88
export { regEffect, DISPATCH_LATER, DISPATCH } from './fx';
99
export { regCoeffect, NOW, RANDOM } from './cofx';
1010
export { regGlobalInterceptor, getGlobalInterceptors, clearGlobalInterceptors } from './settings';
11-
export { getHandler, clearHandlers, clearReactions, clearSubs } from './registrar';
11+
export { getHandler, clearHandlers, clearReactions, clearSubs, getReactions } from './registrar';
1212

1313
export { dispatch } from './router';
1414
export { debounceAndDispatch, throttleAndDispatch } from './debounce'

src/reaction.ts

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -25,12 +25,16 @@ export class Reaction<T> {
2525
return new Reaction(fn, deps)
2626
}
2727

28-
getValue(): T {
28+
computeValue(): T {
2929
this.ensureDirty()
3030
this.recomputeIfNeeded(false)
3131
return this.value as T
3232
}
3333

34+
getValue(): T {
35+
return this.value as T
36+
}
37+
3438
getDepValue(notifyWatchers: boolean = true): [T, number] {
3539
this.recomputeIfNeeded(notifyWatchers)
3640
return [this.value as T, this.version]
@@ -155,9 +159,7 @@ export class Reaction<T> {
155159

156160
private disposeIfUnused() {
157161
if (this.isAlive) return
158-
159-
this.value = undefined
160-
this.version = 0
162+
161163
this.depsVersions = []
162164
this.dirty = false
163165
this.scheduled = false

src/registrar.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,10 @@ export function getReaction(key: string): Reaction<any> | undefined {
6868
return reactionsRegistry.get(key);
6969
}
7070

71+
export function getReactions(): Map<string, Reaction<any>> | undefined {
72+
return reactionsRegistry;
73+
}
74+
7175
export function setReaction(key: string, reaction: Reaction<any>): void {
7276
reactionsRegistry.set(key, reaction);
7377
}

src/subs.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -82,5 +82,5 @@ export function getOrCreateReaction(subVector: SubVector): Reaction<any> {
8282

8383
export function getSubscriptionValue<T>(subVector: SubVector): T {
8484
const reaction = getOrCreateReaction(subVector)
85-
return reaction ? reaction.getValue() : undefined as T
85+
return reaction ? reaction.computeValue() : undefined as T
8686
}

0 commit comments

Comments
 (0)