Skip to content

Commit f26e16e

Browse files
committed
Allow forcing no automatic cleanup.
Fixes: #9
1 parent 4bfb68b commit f26e16e

File tree

2 files changed

+11
-5
lines changed

2 files changed

+11
-5
lines changed

README.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -101,6 +101,11 @@ onDestroyed: ->
101101

102102
But you do not have to! They will be stopped automatically anyway.
103103

104+
If you want to prevent automatically stopping the computed field, maybe
105+
because you are not accessing its value inside an autorun, you can pass
106+
a `true` value as a third argument to its constructor. But be sure to cleanup
107+
the field once you do not need it anymore.
108+
104109
```javascript
105110
field.flush()
106111
```

lib.coffee

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
class ComputedField
2-
constructor: (func, equalsFunc) ->
2+
constructor: (func, equalsFunc, dontStop) ->
33
handle = null
44
lastValue = null
55

@@ -15,10 +15,11 @@ class ComputedField
1515
else
1616
lastValue.set value
1717

18-
Tracker.afterFlush ->
19-
# If there are no dependents anymore, stop the autorun. We will run
20-
# it again in the getter's flush call if needed.
21-
getter.stop() unless lastValue.dep.hasDependents()
18+
unless dontStop
19+
Tracker.afterFlush ->
20+
# If there are no dependents anymore, stop the autorun. We will run
21+
# it again in the getter's flush call if needed.
22+
getter.stop() unless lastValue.dep.hasDependents()
2223

2324
# If something stops our autorun from the outside, we want to know that and update internal state accordingly.
2425
# This means that if computed field was created inside an autorun, and that autorun is invalided our autorun is

0 commit comments

Comments
 (0)