Skip to content

Commit d1f5acb

Browse files
committed
Saner way of accessing first rendered node. Trim trailing whitespace.
1 parent e4dbcff commit d1f5acb

File tree

2 files changed

+20
-20
lines changed

2 files changed

+20
-20
lines changed

src/coconut/diffing/Rendered.hx

+14-14
Original file line numberDiff line numberDiff line change
@@ -14,38 +14,38 @@ class Rendered<Real:{}> {
1414
}
1515

1616
public function first(later):Real {
17-
try each(later, function (r) throw { F: r })
18-
catch (d:Dynamic)
19-
if (d.F != null) return d.F;
20-
else Error.rethrow(d);
21-
return null;
17+
var found = null;
18+
try each(later, function (r) throw found = r)
19+
catch (d:Dynamic)
20+
if (d != found) Error.rethrow(d);
21+
return found;
2222
}
2323

2424
public function each(later:Later, f:Real->Void) {
2525
function rec(children:Array<RNode<Real>>)
2626
for (c in children) switch c {
2727
case RNative(_, r, _): f(r);
28-
case RWidget(w, _):
28+
case RWidget(w, _):
2929
rec(@:privateAccess w._coco_getRender(later).childList);
3030
}
3131
rec(childList);
32-
}
32+
}
3333
}
3434

3535
class TypeRegistry<V> {
36-
36+
3737
var keyed:KeyMap<V>;
3838
var unkeyed:Array<V>;
39-
39+
4040
public function new() {}
4141

4242
public function get(key:Key)
43-
return
44-
if (keyed == null) null
43+
return
44+
if (keyed == null) null
4545
else keyed.get(key);
4646

4747
public function set(key:Key, value) {
48-
if (keyed == null)
48+
if (keyed == null)
4949
keyed = new KeyMap();
5050

5151
#if debug
@@ -59,8 +59,8 @@ class TypeRegistry<V> {
5959
if (unkeyed == null) unkeyed = [];
6060
unkeyed.push(v);
6161
}
62-
63-
public function pull()
62+
63+
public function pull()
6464
return
6565
if (unkeyed == null) null;
6666
else unkeyed.shift();//TODO: find better solution for platforms where shifting is slow

src/coconut/diffing/Widget.hx

+6-6
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ class Widget<Real:{}> {
1616
@:noCompletion var _coco_parent:Widget<Real>;
1717
@:noCompletion var _coco_differ:Differ<Real>;
1818
@:noCompletion var _coco_link:CallbackLink;
19-
19+
2020
public function new(
2121
rendered:Observable<VNode<Real>>,
2222
mounted:Void->Void,
@@ -29,7 +29,7 @@ class Widget<Real:{}> {
2929
case VMany(nodes):
3030
function isEmpty(nodes:Array<VNode<Real>>) {
3131
for (n in nodes) if (n != null) switch n {
32-
case VMany(nodes):
32+
case VMany(nodes):
3333
if (!isEmpty(nodes)) return false;
3434
default: return false;
3535
}
@@ -39,10 +39,10 @@ class Widget<Real:{}> {
3939
else r;
4040
default: r;
4141
});
42-
42+
4343
this._coco_viewMounted = mounted;
4444
this._coco_viewUpdated = updated;
45-
this._coco_viewUnmounting = unmounting;
45+
this._coco_viewUnmounting = unmounting;
4646
}
4747

4848
@:noCompletion function _coco_getRender(later:Later):Rendered<Real> {
@@ -73,7 +73,7 @@ class Widget<Real:{}> {
7373
_coco_invalid = true;
7474
if (_coco_parent != null)
7575
_coco_parent._coco_scheduleChild(this);
76-
else
76+
else
7777
defer(_coco_update.bind(null));
7878
}
7979

@@ -93,7 +93,7 @@ class Widget<Real:{}> {
9393

9494
var previousCount = 0,
9595
first = null;
96-
96+
9797
previous.each(later, function (r) {
9898
if (first == null) first = r;
9999
previousCount++;

0 commit comments

Comments
 (0)