Add initial tools for managing derivations and React compatibility (#202)

Co-authored-by: Cole Lawrence <cole@colelawrence.com>
Co-authored-by: Elliot <key.draw@gmail.com>
Co-authored-by: Aria <aria.minaei@gmail.com>
This commit is contained in:
Cole Lawrence 2022-06-09 13:12:40 -04:00 committed by GitHub
parent bebf281517
commit f1844952ea
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
12 changed files with 320 additions and 30 deletions

View file

@ -170,9 +170,9 @@ export default abstract class AbstractDerivation<V> implements IDerivation<V> {
this._didMarkDependentsAsStale = true
this._isFresh = false
this._dependents.forEach((dependent) => {
for (const dependent of this._dependents) {
dependent(this)
})
}
}
/**
@ -228,14 +228,14 @@ export default abstract class AbstractDerivation<V> implements IDerivation<V> {
this._didMarkDependentsAsStale = false
this._isFresh = false
if (shouldBecomeHot) {
this._dependencies.forEach((d) => {
for (const d of this._dependencies) {
d.addDependent(this._internal_markAsStale)
})
}
this._keepHot()
} else {
this._dependencies.forEach((d) => {
for (const d of this._dependencies) {
d.removeDependent(this._internal_markAsStale)
})
}
this._becomeCold()
}
}

View file

@ -70,18 +70,18 @@ export class PrismDerivation<V> extends AbstractDerivation<V> {
popCollector(collector)
this._dependencies.forEach((dep) => {
for (const dep of this._dependencies) {
if (!newDeps.has(dep)) {
this._removeDependency(dep)
}
})
}
this._dependencies = newDeps
startIgnoringDependencies()
newDeps.forEach((dep) => {
for (const dep of newDeps) {
this._cacheOfDendencyValues.set(dep, dep.getValue())
})
}
stopIgnoringDependencies()
return value!