Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Multitarget #9

Merged
merged 9 commits into from
Apr 23, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .haxerc
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
{
"version": "4.0.0",
"version": "4.0.5",
"resolveLibs": "scoped"
}
5 changes: 2 additions & 3 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -17,15 +17,14 @@ os:
# - osx

env:
- HAXE_VERSION=3.4.7
- HAXE_VERSION=stable
- HAXE_VERSION=nightly

install:
- npm i -g lix
- lix install haxe $HAXE_VERSION
- lix download

script:
- lix run travix js

Expand Down
9 changes: 5 additions & 4 deletions dev.hxml
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
tests.hxml
-lib travix
-lib coconut.diffing
-js bin/js/tests.js
-cp tests
-main Main
-lib coconut.vdom
-js bin/js/tests.js
-dce full
2 changes: 0 additions & 2 deletions extraParams.hxml

This file was deleted.

3 changes: 1 addition & 2 deletions haxe_libraries/coconut.diffing.hxml
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
-D coconut.diffing
-cp src
-lib coconut.ui
extraParams.hxml
-lib coconut.ui
9 changes: 4 additions & 5 deletions haxe_libraries/coconut.ui.hxml
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
-D coconut.ui=0.8.0
# @install: lix --silent download "gh://github.com/MVCoconut/coconut.ui#26ad0cf0994fe24e1c3ca8b003c3f91f13334ec2" into coconut.ui/0.8.0/github/26ad0cf0994fe24e1c3ca8b003c3f91f13334ec2
-lib tink_hxx
# @install: lix --silent download "gh://github.com/MVCoconut/coconut.ui#b75ff3be15d233973c9697cc14c9386df36c2e33" into coconut.ui/0.10.0/github/b75ff3be15d233973c9697cc14c9386df36c2e33
-lib coconut.data
-lib tink_anon
-lib tink_hxx
-lib tink_lang
# -cp ${HAXE_LIBCACHE}/coconut.ui/0.8.0/github/26ad0cf0994fe24e1c3ca8b003c3f91f13334ec2/src
-cp ../coconut.ui/src
-cp ${HAXE_LIBCACHE}/coconut.ui/0.10.0/github/b75ff3be15d233973c9697cc14c9386df36c2e33/src
-D coconut.ui=0.10.0
-D coconut_ui
7 changes: 3 additions & 4 deletions haxe_libraries/coconut.vdom.hxml
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
-D coconut.vdom=0.5.0
# @install: lix --silent download "gh://github.com/MVCoconut/coconut.vdom#82922f3ab6c085719408e24934130c9f73b3d078" into coconut.vdom/0.5.0/github/82922f3ab6c085719408e24934130c9f73b3d078
# @install: lix --silent download "gh://github.com/MVCoconut/coconut.vdom#cbcf07e7a29664063027cdcbd3f5dba4ac3bd1b3" into coconut.vdom/0.7.2/github/cbcf07e7a29664063027cdcbd3f5dba4ac3bd1b3
-lib coconut.diffing
-lib xDOM
-cp ../coconut.vdom/src
--macro coconut.vdom.macros.Setup.all()
-cp ${HAXE_LIBCACHE}/coconut.vdom/0.7.2/github/cbcf07e7a29664063027cdcbd3f5dba4ac3bd1b3/src
-D coconut.vdom=0.7.2
6 changes: 3 additions & 3 deletions haxe_libraries/tink_anon.hxml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
-D tink_anon=0.4.1
# @install: lix --silent download "haxelib:/tink_anon#0.4.1" into tink_anon/0.4.1/haxelib
# @install: lix --silent download "haxelib:/tink_anon#0.5.0" into tink_anon/0.5.0/haxelib
-lib tink_macro
-cp ${HAXE_LIBCACHE}/tink_anon/0.4.1/haxelib/src
-cp ${HAXE_LIBCACHE}/tink_anon/0.5.0/haxelib/src
-D tink_anon=0.5.0
3 changes: 3 additions & 0 deletions haxe_libraries/tink_chunk.hxml
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
# @install: lix --silent download "haxelib:/tink_chunk#0.3.1" into tink_chunk/0.3.1/haxelib
-cp ${HAXE_LIBCACHE}/tink_chunk/0.3.1/haxelib/src
-D tink_chunk=0.3.1
8 changes: 8 additions & 0 deletions haxe_libraries/tink_cli.hxml
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
# @install: lix --silent download "haxelib:/tink_cli#0.5.0" into tink_cli/0.5.0/haxelib
-lib tink_io
-lib tink_macro
-lib tink_stringly
-cp ${HAXE_LIBCACHE}/tink_cli/0.5.0/haxelib/src
-D tink_cli=0.5.0
# Make sure docs are generated
-D use-rtti-doc
6 changes: 3 additions & 3 deletions haxe_libraries/tink_core.hxml
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
-D tink_core=1.24.0
# @install: lix --silent download "haxelib:/tink_core#1.24.0" into tink_core/1.24.0/haxelib
-cp ${HAXE_LIBCACHE}/tink_core/1.24.0/haxelib/src
# @install: lix --silent download "haxelib:/tink_core#1.26.0" into tink_core/1.26.0/haxelib
-cp ${HAXE_LIBCACHE}/tink_core/1.26.0/haxelib/src
-D tink_core=1.26.0
6 changes: 3 additions & 3 deletions haxe_libraries/tink_hxx.hxml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
-D tink_hxx=0.22.2
# @install: lix --silent download "haxelib:/tink_hxx#0.22.2" into tink_hxx/0.22.2/haxelib
# @install: lix --silent download "haxelib:/tink_hxx#0.23.0" into tink_hxx/0.23.0/haxelib
-lib html-entities
-lib tink_anon
-lib tink_parse
-cp ${HAXE_LIBCACHE}/tink_hxx/0.22.2/haxelib/src
-cp ${HAXE_LIBCACHE}/tink_hxx/0.23.0/haxelib/src
-D tink_hxx=0.23.0
5 changes: 5 additions & 0 deletions haxe_libraries/tink_io.hxml
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
# @install: lix --silent download "haxelib:/tink_io#0.7.1" into tink_io/0.7.1/haxelib
-lib tink_chunk
-lib tink_streams
-cp ${HAXE_LIBCACHE}/tink_io/0.7.1/haxelib/src
-D tink_io=0.7.1
6 changes: 3 additions & 3 deletions haxe_libraries/tink_macro.hxml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
-D tink_macro=0.18.0
# @install: lix --silent download "haxelib:/tink_macro#0.18.0" into tink_macro/0.18.0/haxelib
# @install: lix --silent download "haxelib:/tink_macro#0.19.0" into tink_macro/0.19.0/haxelib
-lib tink_core
-cp ${HAXE_LIBCACHE}/tink_macro/0.18.0/haxelib/src
-cp ${HAXE_LIBCACHE}/tink_macro/0.19.0/haxelib/src
-D tink_macro=0.19.0
6 changes: 3 additions & 3 deletions haxe_libraries/tink_state.hxml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
-D tink_state=0.11.0
# @install: lix --silent download "haxelib:/tink_state#0.11.0" into tink_state/0.11.0/haxelib
# @install: lix --silent download "gh://github.com/haxetink/tink_state#2c1770b52411491e8aaba22cb8b85ddad1dc9ccb" into tink_state/0.11.0/github/2c1770b52411491e8aaba22cb8b85ddad1dc9ccb
-lib tink_core
-cp ${HAXE_LIBCACHE}/tink_state/0.11.0/haxelib/src
-cp ${HAXE_LIBCACHE}/tink_state/0.11.0/github/2c1770b52411491e8aaba22cb8b85ddad1dc9ccb/src
-D tink_state=0.11.0
6 changes: 6 additions & 0 deletions haxe_libraries/tink_streams.hxml
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
# @install: lix --silent download "haxelib:/tink_streams#0.3.2" into tink_streams/0.3.2/haxelib
-lib tink_core
-cp ${HAXE_LIBCACHE}/tink_streams/0.3.2/haxelib/src
-D tink_streams=0.3.2
# temp for development, delete this file when pure branch merged
-D pure
4 changes: 4 additions & 0 deletions haxe_libraries/tink_stringly.hxml
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
# @install: lix --silent download "haxelib:/tink_stringly#0.4.0" into tink_stringly/0.4.0/haxelib
-lib tink_core
-cp ${HAXE_LIBCACHE}/tink_stringly/0.4.0/haxelib/src
-D tink_stringly=0.4.0
10 changes: 6 additions & 4 deletions haxe_libraries/travix.hxml
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
# @run: haxelib run-dir travix ${HAXESHIM_LIBCACHE}/travix/0.10.5/haxelib
# @install: lix --silent download "haxelib:travix#0.10.5" into travix/0.10.5/haxelib
-D travix=0.10.5
-cp ${HAXESHIM_LIBCACHE}/travix/0.10.5/haxelib/src
# @install: lix --silent download "haxelib:/travix#0.14.0" into travix/0.14.0/haxelib
# @post-install: cd ${HAXE_LIBCACHE}/travix/0.14.0/haxelib && haxe -cp src --run travix.PostDownload
# @run: haxelib run-dir travix ${HAXE_LIBCACHE}/travix/0.14.0/haxelib
-lib tink_cli
-cp ${HAXE_LIBCACHE}/travix/0.14.0/haxelib/src
-D travix=0.14.0
2 changes: 1 addition & 1 deletion src/coconut/diffing/Differ.hx
Original file line number Diff line number Diff line change
Expand Up @@ -167,7 +167,7 @@ class Differ<Real:{}> {
case null:
renderAll(nodes, parent, later);
case v:
v.each(later, function (_) lastCount++);
lastCount = v.justCount();
updateAll(v, nodes, parent, later);
}

Expand Down
37 changes: 23 additions & 14 deletions src/coconut/diffing/Rendered.hx
Original file line number Diff line number Diff line change
Expand Up @@ -14,38 +14,47 @@ class Rendered<Real:{}> {
}

public function first(later):Real {
try each(later, function (r) throw { F: r })
catch (d:Dynamic)
if (d.F != null) return d.F;
else Error.rethrow(d);
return null;
var found = null;
try each(later, function (r) throw found = r)
catch (d:Dynamic)
if (d != found) Error.rethrow(d);
return found;
}

public function justCount() {
var ret = 0;
for (c in childList) ret += switch c {
case RNative(_, _, _): 1;
case RWidget(w, _): @:privateAccess w._coco_lastRender.justCount();
}
return ret;
}

public function each(later:Later, f:Real->Void) {
function rec(children:Array<RNode<Real>>)
for (c in children) switch c {
case RNative(_, r, _): f(r);
case RWidget(w, _):
case RWidget(w, _):
rec(@:privateAccess w._coco_getRender(later).childList);
}
rec(childList);
}
}
}

class TypeRegistry<V> {

var keyed:KeyMap<V>;
var unkeyed:Array<V>;

public function new() {}

public function get(key:Key)
return
if (keyed == null) null
return
if (keyed == null) null
else keyed.get(key);

public function set(key:Key, value) {
if (keyed == null)
if (keyed == null)
keyed = new KeyMap();

#if debug
Expand All @@ -59,8 +68,8 @@ class TypeRegistry<V> {
if (unkeyed == null) unkeyed = [];
unkeyed.push(v);
}
public function pull()

public function pull()
return
if (unkeyed == null) null;
else unkeyed.shift();//TODO: find better solution for platforms where shifting is slow
Expand Down
6 changes: 3 additions & 3 deletions src/coconut/diffing/VNode.hx
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,11 @@ import coconut.diffing.NodeType;

@:pure
abstract VNode<Real:{}>(VNodeData<Real>) from VNodeData<Real> to VNodeData<Real> {
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

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>
return cast VNative(type, ref, key, attr, cast children);

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

Expand Down
12 changes: 6 additions & 6 deletions src/coconut/diffing/Widget.hx
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ class Widget<Real:{}> {
@:noCompletion var _coco_parent:Widget<Real>;
@:noCompletion var _coco_differ:Differ<Real>;
@:noCompletion var _coco_link:CallbackLink;

public function new(
rendered:Observable<VNode<Real>>,
mounted:Void->Void,
Expand All @@ -29,7 +29,7 @@ class Widget<Real:{}> {
case VMany(nodes):
function isEmpty(nodes:Array<VNode<Real>>) {
for (n in nodes) if (n != null) switch n {
case VMany(nodes):
case VMany(nodes):
if (!isEmpty(nodes)) return false;
default: return false;
}
Expand All @@ -39,10 +39,10 @@ class Widget<Real:{}> {
else r;
default: r;
});

this._coco_viewMounted = mounted;
this._coco_viewUpdated = updated;
this._coco_viewUnmounting = unmounting;
this._coco_viewUnmounting = unmounting;
}

@:noCompletion function _coco_getRender(later:Later):Rendered<Real> {
Expand Down Expand Up @@ -73,7 +73,7 @@ class Widget<Real:{}> {
_coco_invalid = true;
if (_coco_parent != null)
_coco_parent._coco_scheduleChild(this);
else
else
defer(_coco_update.bind(null));
}

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

var previousCount = 0,
first = null;

previous.each(later, function (r) {
if (first == null) first = r;
previousCount++;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,13 @@ import haxe.macro.Expr;
using tink.MacroApi;
using Lambda;

class Setup {
class ViewBuilder {

static function all()

coconut.ui.macros.ViewBuilder.afterBuild.whenever(function (ctx) {
static public function init(renders)
return coconut.ui.macros.ViewBuilder.init(renders, function (ctx) {
var t = ctx.target.target.name.asComplexType([for(p in ctx.target.target.params) TPType(p.t.toComplex())]);
var attributes = TAnonymous(ctx.attributes);

var def = macro class {
static var __type = {
create: $i{ctx.target.target.name}.new,
Expand All @@ -25,19 +24,19 @@ class Setup {
@:optional var ref(default, never):coconut.ui.Ref<$t>;
},
attributes:$attributes
):coconut.ui.RenderResult
):$renders
return coconut.diffing.VNode.VNodeData.VWidget(cast __type, hxxMeta.ref, hxxMeta.key, attributes);
}

switch def.fields.find(function(f) return f.name == 'fromHxx').kind {
case FFun(f): f.params = ctx.target.target.params.map(typeParameterToTypeParamDecl);
case _: // unreachable
}

ctx.target.addMembers(def);

});

// TODO: this should go tink_macro
static function typeParameterToTypeParamDecl(p:haxe.macro.Type.TypeParameter):TypeParamDecl {
return {
Expand Down
2 changes: 1 addition & 1 deletion tests.hxml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
-cp tests
-main Main
-main RunTests
-dce full
-lib coconut.vdom
4 changes: 2 additions & 2 deletions tests/RunTests.hx
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
package ;

import coconut.diffing.Differ;
import Main;

class RunTests {

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

}