Mark add/removeDependent() as internal

This commit is contained in:
Aria Minaei 2022-12-01 14:11:06 +01:00
parent 194de8d833
commit a073984b2f
2 changed files with 19 additions and 16 deletions

View file

@ -38,18 +38,21 @@ export interface IDerivation<V> {
* *
* @param d - The derivation to be made a dependent of this derivation. * @param d - The derivation to be made a dependent of this derivation.
* *
* @see removeDependent * @see _removeDependent
*
* @internal
*/ */
addDependent(d: IDependent): void _addDependent(d: IDependent): void
/** /**
* Remove a derivation as a dependent of this derivation. * Remove a derivation as a dependent of this derivation.
* *
* @param d - The derivation to be removed from as a dependent of this derivation. * @param d - The derivation to be removed from as a dependent of this derivation.
* *
* @see addDependent * @see _addDependent
* @internal
*/ */
removeDependent(d: IDependent): void _removeDependent(d: IDependent): void
/** /**
* Gets the current value of the derivation. If the value is stale, it causes the derivation to freshen. * Gets the current value of the derivation. If the value is stale, it causes the derivation to freshen.

View file

@ -55,7 +55,7 @@ class HotHandle<V> {
private readonly _prismInstance: PrismDerivation<V>, private readonly _prismInstance: PrismDerivation<V>,
) { ) {
for (const d of this._dependencies) { for (const d of this._dependencies) {
d.addDependent(this._reactToDependencyGoingStale) d._addDependent(this._reactToDependencyGoingStale)
} }
startIgnoringDependencies() startIgnoringDependencies()
@ -75,7 +75,7 @@ class HotHandle<V> {
destroy() { destroy() {
for (const d of this._dependencies) { for (const d of this._dependencies) {
d.removeDependent(this._reactToDependencyGoingStale) d._removeDependent(this._reactToDependencyGoingStale)
} }
cleanupScopeStack(this._scope) cleanupScopeStack(this._scope)
} }
@ -186,7 +186,7 @@ class HotHandle<V> {
protected _addDependency(d: IDerivation<$IntentionalAny>) { protected _addDependency(d: IDerivation<$IntentionalAny>) {
if (this._dependencies.has(d)) return if (this._dependencies.has(d)) return
this._dependencies.add(d) this._dependencies.add(d)
d.addDependent(this._reactToDependencyGoingStale) d._addDependent(this._reactToDependencyGoingStale)
} }
/** /**
@ -195,7 +195,7 @@ class HotHandle<V> {
protected _removeDependency(d: IDerivation<$IntentionalAny>) { protected _removeDependency(d: IDerivation<$IntentionalAny>) {
if (!this._dependencies.has(d)) return if (!this._dependencies.has(d)) return
this._dependencies.delete(d) this._dependencies.delete(d)
d.removeDependent(this._reactToDependencyGoingStale) d._removeDependent(this._reactToDependencyGoingStale)
} }
} }
@ -242,7 +242,7 @@ class PrismDerivation<V> implements IDerivation<V> {
listener(newValue) listener(newValue)
} }
this.addDependent(dependent) this._addDependent(dependent)
if (immediate) { if (immediate) {
lastValue = this.getValue() lastValue = this.getValue()
@ -250,7 +250,7 @@ class PrismDerivation<V> implements IDerivation<V> {
} }
const unsubscribe = () => { const unsubscribe = () => {
this.removeDependent(dependent) this._removeDependent(dependent)
} }
return unsubscribe return unsubscribe
@ -261,10 +261,10 @@ class PrismDerivation<V> implements IDerivation<V> {
*/ */
onStale(callback: () => void): VoidFn { onStale(callback: () => void): VoidFn {
const untap = () => { const untap = () => {
this.removeDependent(fn) this._removeDependent(fn)
} }
const fn = () => callback() const fn = () => callback()
this.addDependent(fn) this._addDependent(fn)
return untap return untap
} }
@ -280,9 +280,9 @@ class PrismDerivation<V> implements IDerivation<V> {
* *
* @param d - The derivation to be made a dependent of this derivation. * @param d - The derivation to be made a dependent of this derivation.
* *
* @see removeDependent * @see _removeDependent
*/ */
addDependent(d: IDependent) { _addDependent(d: IDependent) {
if (!this._state.hot) { if (!this._state.hot) {
this._goHot() this._goHot()
} }
@ -302,9 +302,9 @@ class PrismDerivation<V> implements IDerivation<V> {
* *
* @param d - The derivation to be removed from as a dependent of this derivation. * @param d - The derivation to be removed from as a dependent of this derivation.
* *
* @see addDependent * @see _addDependent
*/ */
removeDependent(d: IDependent) { _removeDependent(d: IDependent) {
const state = this._state const state = this._state
if (!state.hot) { if (!state.hot) {
return return