Skip to content

Commit

Permalink
Working towards #10, this might be enough
Browse files Browse the repository at this point in the history
  • Loading branch information
wartman committed Dec 3, 2024
1 parent 1045fa3 commit 9f68a6c
Show file tree
Hide file tree
Showing 4 changed files with 27 additions and 8 deletions.
4 changes: 4 additions & 0 deletions src/blok/core/DisposableCollection.hx
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,10 @@ final class DisposableCollection implements Disposable implements DisposableHost
disposables.remove(disposable);
}

public function count() {
return disposables.length;
}

public function dispose() {
isDisposed = true;
for (disposable in disposables) {
Expand Down
27 changes: 21 additions & 6 deletions src/blok/signal/Isolate.hx → src/blok/core/Isolate.hx
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
package blok.signal;
package blok.core;

import blok.core.*;
import blok.debug.Debug;

@:forward
abstract Isolate<T>(IsolateImpl<T>) to Disposable to DisposableItem {
Expand All @@ -22,7 +22,7 @@ abstract Isolate<T>(IsolateImpl<T>) to Disposable to DisposableItem {
class IsolateImpl<T> implements Disposable {
final scope:() -> T;

var owner:Owner;
var owner:Null<Owner>;

public function new(scope) {
this.scope = scope;
Expand All @@ -31,13 +31,28 @@ class IsolateImpl<T> implements Disposable {

public function get():T {
cleanup();
owner = new Owner();
assert(owner != null);
return owner.own(scope);
}

public function cleanup() {
owner?.dispose();
owner = null;
if (owner == null) {
owner = new Owner();
return;
}

var count = owner.disposables.count();

if (count == 0) {
return;
}

#if debug
warn('Captured ${count} disposables while running an Isolate -- try to get this down to 0 for best performance');
#end

owner.dispose();
owner = new Owner();
}

public function dispose() {
Expand Down
1 change: 1 addition & 0 deletions src/blok/core/Owner.hx
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package blok.core;

@:allow(blok.core)
class Owner implements DisposableHost implements Disposable {
static var currentOwner:Null<DisposableHost> = null;

Expand Down
3 changes: 1 addition & 2 deletions src/blok/ui/ProxyView.hx
Original file line number Diff line number Diff line change
@@ -1,11 +1,10 @@
package blok.ui;

import blok.adaptor.Cursor;
import blok.core.Owner;
import blok.core.*;
import blok.debug.Debug;
import blok.diffing.Differ;
import blok.signal.Computation;
import blok.signal.Isolate;

using blok.boundary.BoundaryTools;

Expand Down

0 comments on commit 9f68a6c

Please sign in to comment.