Skip to content

Commit be0ef43

Browse files
authored
Merge pull request #9 from MVCoconut/multitarget
Multitarget
2 parents f738189 + 20196c6 commit be0ef43

25 files changed

+107
-76
lines changed

.haxerc

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
11
{
2-
"version": "4.0.0",
2+
"version": "4.0.5",
33
"resolveLibs": "scoped"
44
}

.travis.yml

+2-3
Original file line numberDiff line numberDiff line change
@@ -17,15 +17,14 @@ os:
1717
# - osx
1818

1919
env:
20-
- HAXE_VERSION=3.4.7
2120
- HAXE_VERSION=stable
2221
- HAXE_VERSION=nightly
23-
22+
2423
install:
2524
- npm i -g lix
2625
- lix install haxe $HAXE_VERSION
2726
- lix download
28-
27+
2928
script:
3029
- lix run travix js
3130

dev.hxml

+5-4
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
1-
tests.hxml
2-
-lib travix
3-
-lib coconut.diffing
4-
-js bin/js/tests.js
1+
-cp tests
2+
-main Main
3+
-lib coconut.vdom
4+
-js bin/js/tests.js
5+
-dce full

extraParams.hxml

-2
This file was deleted.

haxe_libraries/coconut.diffing.hxml

+1-2
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
11
-D coconut.diffing
22
-cp src
3-
-lib coconut.ui
4-
extraParams.hxml
3+
-lib coconut.ui

haxe_libraries/coconut.ui.hxml

+4-5
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,8 @@
1-
-D coconut.ui=0.8.0
2-
# @install: lix --silent download "gh://github.com/MVCoconut/coconut.ui#26ad0cf0994fe24e1c3ca8b003c3f91f13334ec2" into coconut.ui/0.8.0/github/26ad0cf0994fe24e1c3ca8b003c3f91f13334ec2
3-
-lib tink_hxx
1+
# @install: lix --silent download "gh://github.com/MVCoconut/coconut.ui#b75ff3be15d233973c9697cc14c9386df36c2e33" into coconut.ui/0.10.0/github/b75ff3be15d233973c9697cc14c9386df36c2e33
42
-lib coconut.data
53
-lib tink_anon
4+
-lib tink_hxx
65
-lib tink_lang
7-
# -cp ${HAXE_LIBCACHE}/coconut.ui/0.8.0/github/26ad0cf0994fe24e1c3ca8b003c3f91f13334ec2/src
8-
-cp ../coconut.ui/src
6+
-cp ${HAXE_LIBCACHE}/coconut.ui/0.10.0/github/b75ff3be15d233973c9697cc14c9386df36c2e33/src
7+
-D coconut.ui=0.10.0
98
-D coconut_ui

haxe_libraries/coconut.vdom.hxml

+3-4
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
1-
-D coconut.vdom=0.5.0
2-
# @install: lix --silent download "gh://github.com/MVCoconut/coconut.vdom#82922f3ab6c085719408e24934130c9f73b3d078" into coconut.vdom/0.5.0/github/82922f3ab6c085719408e24934130c9f73b3d078
1+
# @install: lix --silent download "gh://github.com/MVCoconut/coconut.vdom#cbcf07e7a29664063027cdcbd3f5dba4ac3bd1b3" into coconut.vdom/0.7.2/github/cbcf07e7a29664063027cdcbd3f5dba4ac3bd1b3
32
-lib coconut.diffing
43
-lib xDOM
5-
-cp ../coconut.vdom/src
6-
--macro coconut.vdom.macros.Setup.all()
4+
-cp ${HAXE_LIBCACHE}/coconut.vdom/0.7.2/github/cbcf07e7a29664063027cdcbd3f5dba4ac3bd1b3/src
5+
-D coconut.vdom=0.7.2

haxe_libraries/tink_anon.hxml

+3-3
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
-D tink_anon=0.4.1
2-
# @install: lix --silent download "haxelib:/tink_anon#0.4.1" into tink_anon/0.4.1/haxelib
1+
# @install: lix --silent download "haxelib:/tink_anon#0.5.0" into tink_anon/0.5.0/haxelib
32
-lib tink_macro
4-
-cp ${HAXE_LIBCACHE}/tink_anon/0.4.1/haxelib/src
3+
-cp ${HAXE_LIBCACHE}/tink_anon/0.5.0/haxelib/src
4+
-D tink_anon=0.5.0

haxe_libraries/tink_chunk.hxml

+3
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
# @install: lix --silent download "haxelib:/tink_chunk#0.3.1" into tink_chunk/0.3.1/haxelib
2+
-cp ${HAXE_LIBCACHE}/tink_chunk/0.3.1/haxelib/src
3+
-D tink_chunk=0.3.1

haxe_libraries/tink_cli.hxml

+8
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
# @install: lix --silent download "haxelib:/tink_cli#0.5.0" into tink_cli/0.5.0/haxelib
2+
-lib tink_io
3+
-lib tink_macro
4+
-lib tink_stringly
5+
-cp ${HAXE_LIBCACHE}/tink_cli/0.5.0/haxelib/src
6+
-D tink_cli=0.5.0
7+
# Make sure docs are generated
8+
-D use-rtti-doc

haxe_libraries/tink_core.hxml

+3-3
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
1-
-D tink_core=1.24.0
2-
# @install: lix --silent download "haxelib:/tink_core#1.24.0" into tink_core/1.24.0/haxelib
3-
-cp ${HAXE_LIBCACHE}/tink_core/1.24.0/haxelib/src
1+
# @install: lix --silent download "haxelib:/tink_core#1.26.0" into tink_core/1.26.0/haxelib
2+
-cp ${HAXE_LIBCACHE}/tink_core/1.26.0/haxelib/src
3+
-D tink_core=1.26.0

haxe_libraries/tink_hxx.hxml

+3-3
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
1-
-D tink_hxx=0.22.2
2-
# @install: lix --silent download "haxelib:/tink_hxx#0.22.2" into tink_hxx/0.22.2/haxelib
1+
# @install: lix --silent download "haxelib:/tink_hxx#0.23.0" into tink_hxx/0.23.0/haxelib
32
-lib html-entities
43
-lib tink_anon
54
-lib tink_parse
6-
-cp ${HAXE_LIBCACHE}/tink_hxx/0.22.2/haxelib/src
5+
-cp ${HAXE_LIBCACHE}/tink_hxx/0.23.0/haxelib/src
6+
-D tink_hxx=0.23.0

haxe_libraries/tink_io.hxml

+5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
# @install: lix --silent download "haxelib:/tink_io#0.7.1" into tink_io/0.7.1/haxelib
2+
-lib tink_chunk
3+
-lib tink_streams
4+
-cp ${HAXE_LIBCACHE}/tink_io/0.7.1/haxelib/src
5+
-D tink_io=0.7.1

haxe_libraries/tink_macro.hxml

+3-3
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
-D tink_macro=0.18.0
2-
# @install: lix --silent download "haxelib:/tink_macro#0.18.0" into tink_macro/0.18.0/haxelib
1+
# @install: lix --silent download "haxelib:/tink_macro#0.19.0" into tink_macro/0.19.0/haxelib
32
-lib tink_core
4-
-cp ${HAXE_LIBCACHE}/tink_macro/0.18.0/haxelib/src
3+
-cp ${HAXE_LIBCACHE}/tink_macro/0.19.0/haxelib/src
4+
-D tink_macro=0.19.0

haxe_libraries/tink_state.hxml

+3-3
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
-D tink_state=0.11.0
2-
# @install: lix --silent download "haxelib:/tink_state#0.11.0" into tink_state/0.11.0/haxelib
1+
# @install: lix --silent download "gh://github.com/haxetink/tink_state#2c1770b52411491e8aaba22cb8b85ddad1dc9ccb" into tink_state/0.11.0/github/2c1770b52411491e8aaba22cb8b85ddad1dc9ccb
32
-lib tink_core
4-
-cp ${HAXE_LIBCACHE}/tink_state/0.11.0/haxelib/src
3+
-cp ${HAXE_LIBCACHE}/tink_state/0.11.0/github/2c1770b52411491e8aaba22cb8b85ddad1dc9ccb/src
4+
-D tink_state=0.11.0

haxe_libraries/tink_streams.hxml

+6
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
# @install: lix --silent download "haxelib:/tink_streams#0.3.2" into tink_streams/0.3.2/haxelib
2+
-lib tink_core
3+
-cp ${HAXE_LIBCACHE}/tink_streams/0.3.2/haxelib/src
4+
-D tink_streams=0.3.2
5+
# temp for development, delete this file when pure branch merged
6+
-D pure

haxe_libraries/tink_stringly.hxml

+4
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
# @install: lix --silent download "haxelib:/tink_stringly#0.4.0" into tink_stringly/0.4.0/haxelib
2+
-lib tink_core
3+
-cp ${HAXE_LIBCACHE}/tink_stringly/0.4.0/haxelib/src
4+
-D tink_stringly=0.4.0

haxe_libraries/travix.hxml

+6-4
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
1-
# @run: haxelib run-dir travix ${HAXESHIM_LIBCACHE}/travix/0.10.5/haxelib
2-
# @install: lix --silent download "haxelib:travix#0.10.5" into travix/0.10.5/haxelib
3-
-D travix=0.10.5
4-
-cp ${HAXESHIM_LIBCACHE}/travix/0.10.5/haxelib/src
1+
# @install: lix --silent download "haxelib:/travix#0.14.0" into travix/0.14.0/haxelib
2+
# @post-install: cd ${HAXE_LIBCACHE}/travix/0.14.0/haxelib && haxe -cp src --run travix.PostDownload
3+
# @run: haxelib run-dir travix ${HAXE_LIBCACHE}/travix/0.14.0/haxelib
4+
-lib tink_cli
5+
-cp ${HAXE_LIBCACHE}/travix/0.14.0/haxelib/src
6+
-D travix=0.14.0

src/coconut/diffing/Differ.hx

+1-1
Original file line numberDiff line numberDiff line change
@@ -167,7 +167,7 @@ class Differ<Real:{}> {
167167
case null:
168168
renderAll(nodes, parent, later);
169169
case v:
170-
v.each(later, function (_) lastCount++);
170+
lastCount = v.justCount();
171171
updateAll(v, nodes, parent, later);
172172
}
173173

src/coconut/diffing/Rendered.hx

+23-14
Original file line numberDiff line numberDiff line change
@@ -14,38 +14,47 @@ 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;
22+
}
23+
24+
public function justCount() {
25+
var ret = 0;
26+
for (c in childList) ret += switch c {
27+
case RNative(_, _, _): 1;
28+
case RWidget(w, _): @:privateAccess w._coco_lastRender.justCount();
29+
}
30+
return ret;
2231
}
2332

2433
public function each(later:Later, f:Real->Void) {
2534
function rec(children:Array<RNode<Real>>)
2635
for (c in children) switch c {
2736
case RNative(_, r, _): f(r);
28-
case RWidget(w, _):
37+
case RWidget(w, _):
2938
rec(@:privateAccess w._coco_getRender(later).childList);
3039
}
3140
rec(childList);
32-
}
41+
}
3342
}
3443

3544
class TypeRegistry<V> {
36-
45+
3746
var keyed:KeyMap<V>;
3847
var unkeyed:Array<V>;
39-
48+
4049
public function new() {}
4150

4251
public function get(key:Key)
43-
return
44-
if (keyed == null) null
52+
return
53+
if (keyed == null) null
4554
else keyed.get(key);
4655

4756
public function set(key:Key, value) {
48-
if (keyed == null)
57+
if (keyed == null)
4958
keyed = new KeyMap();
5059

5160
#if debug
@@ -59,8 +68,8 @@ class TypeRegistry<V> {
5968
if (unkeyed == null) unkeyed = [];
6069
unkeyed.push(v);
6170
}
62-
63-
public function pull()
71+
72+
public function pull()
6473
return
6574
if (unkeyed == null) null;
6675
else unkeyed.shift();//TODO: find better solution for platforms where shifting is slow

src/coconut/diffing/VNode.hx

+3-3
Original file line numberDiff line numberDiff line change
@@ -4,11 +4,11 @@ import coconut.diffing.NodeType;
44

55
@:pure
66
abstract VNode<Real:{}>(VNodeData<Real>) from VNodeData<Real> to VNodeData<Real> {
7-
8-
static public inline function native<Attr, Real:{}>(type:NodeType<Attr, Real>, ref:Real->Void, key:Key, attr:Attr, ?children:coconut.ui.Children):coconut.ui.RenderResult
7+
8+
static public inline function native<Attr, Real:{}>(type:NodeType<Attr, Real>, ref:Real->Void, key:Key, attr:Attr, ?children:coconut.ui.ChildrenOf<VNode<Real>>):VNode<Real>
99
return cast VNative(type, ref, key, attr, cast children);
1010

11-
static public inline function fragment<R:{}>(attr:{}, children:coconut.ui.Children):VNode<R>
11+
static public inline function fragment<Real:{}>(attr:{}, children:coconut.ui.ChildrenOf<VNode<Real>>):VNode<Real>
1212
return VMany(cast children);
1313
}
1414

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++;

src/coconut/diffing/macros/Setup.hx src/coconut/diffing/macros/ViewBuilder.hx

+8-9
Original file line numberDiff line numberDiff line change
@@ -5,14 +5,13 @@ import haxe.macro.Expr;
55
using tink.MacroApi;
66
using Lambda;
77

8-
class Setup {
8+
class ViewBuilder {
99

10-
static function all()
11-
12-
coconut.ui.macros.ViewBuilder.afterBuild.whenever(function (ctx) {
10+
static public function init(renders)
11+
return coconut.ui.macros.ViewBuilder.init(renders, function (ctx) {
1312
var t = ctx.target.target.name.asComplexType([for(p in ctx.target.target.params) TPType(p.t.toComplex())]);
1413
var attributes = TAnonymous(ctx.attributes);
15-
14+
1615
var def = macro class {
1716
static var __type = {
1817
create: $i{ctx.target.target.name}.new,
@@ -25,19 +24,19 @@ class Setup {
2524
@:optional var ref(default, never):coconut.ui.Ref<$t>;
2625
},
2726
attributes:$attributes
28-
):coconut.ui.RenderResult
27+
):$renders
2928
return coconut.diffing.VNode.VNodeData.VWidget(cast __type, hxxMeta.ref, hxxMeta.key, attributes);
3029
}
31-
30+
3231
switch def.fields.find(function(f) return f.name == 'fromHxx').kind {
3332
case FFun(f): f.params = ctx.target.target.params.map(typeParameterToTypeParamDecl);
3433
case _: // unreachable
3534
}
3635

3736
ctx.target.addMembers(def);
38-
37+
3938
});
40-
39+
4140
// TODO: this should go tink_macro
4241
static function typeParameterToTypeParamDecl(p:haxe.macro.Type.TypeParameter):TypeParamDecl {
4342
return {

tests.hxml

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
11
-cp tests
2-
-main Main
2+
-main RunTests
33
-dce full
44
-lib coconut.vdom

tests/RunTests.hx

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
11
package ;
22

3-
import coconut.diffing.Differ;
3+
import Main;
44

55
class RunTests {
66

77
static function main() {
88
travix.Logger.println('it works');
99
travix.Logger.exit(0); // make sure we exit properly, which is necessary on some targets, e.g. flash & (phantom)js
1010
}
11-
11+
1212
}

0 commit comments

Comments
 (0)