Skip to content

Commit 5e25971

Browse files
committed
Failing test for #8.
1 parent fb6e8f2 commit 5e25971

File tree

6 files changed

+85
-6
lines changed

6 files changed

+85
-6
lines changed

haxe_libraries/tink_pure.hxml

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1-
# @install: lix --silent download "haxelib:tink_pure#0.3.2" into tink_pure/0.3.2/haxelib
2-
-D tink_pure=0.3.2
3-
-cp ${HAXESHIM_LIBCACHE}/tink_pure/0.3.2/haxelib/src
1+
# @install: lix --silent download "gh://github.com/haxetink/tink_pure#f93e378516aeda3b31487c09f46300714b86a49a" into tink_pure/0.5.2/github/f93e378516aeda3b31487c09f46300714b86a49a
2+
-lib tink_core
3+
-lib tink_slice
4+
-cp ${HAXE_LIBCACHE}/tink_pure/0.5.2/github/f93e378516aeda3b31487c09f46300714b86a49a/src
5+
-D tink_pure=0.5.2

src/coconut/react/Renderer.hx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ class Renderer {
44

55
#if !macro
66
static public inline function updateAll()
7-
ViewBase.updateAll();
7+
tink.state.Observable.updateAll();
88
#end
99

1010
static public macro function hxx(e)

tests.hxml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
-cp tests
22
-main RunTests
33
-dce full
4-
4+
-D no-deprecation-warnings
55
-lib tink_unittest

tests/Issue8.hx

Lines changed: 75 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,75 @@
1+
import react.ReactComponent;
2+
import tink.pure.*;
3+
import tink.state.*;
4+
import coconut.ui.*;
5+
import coconut.data.*;
6+
import coconut.react.Renderer.*;
7+
import js.Browser.*;
8+
9+
using tink.CoreApi;
10+
11+
@:asserts
12+
class Issue8 {
13+
static final msgs = [];
14+
static public function log(v)
15+
msgs.push(v);
16+
17+
public function new() {}
18+
public function test() {
19+
var rendered = ReactTestRenderer.create(hxx('<Root />'));
20+
asserts.assert(msgs.length == 2);
21+
rendered.root.findByType(Div).props.onclick();
22+
updateAll();
23+
asserts.assert(msgs.length == 3);
24+
return asserts.done();
25+
}
26+
}
27+
28+
class Root extends View {
29+
30+
@:attr var value:Value<Vector<Obj>, Vector<Obj>> = new Value({
31+
raw: new State(([{foo: 'bar'}]:Vector<Obj>)),
32+
parse: Success,
33+
});
34+
35+
function render() {
36+
Issue8.log('render Root ${value.raw.length}');
37+
return @hxx '
38+
<>
39+
<for ${i in 0...value.raw.length}>
40+
<Sub value=${value.sub(raw -> raw[i], (raw, nu) -> raw.with(i, nu), Success)} onClick=${value.raw = []}/>
41+
</for>
42+
</>
43+
';
44+
}
45+
}
46+
47+
typedef Obj = {
48+
final foo:String;
49+
}
50+
51+
class Sub extends View {
52+
@:attr var value:Value<Obj, Obj>;
53+
@:attr var onClick:Void->Void;
54+
function render() {
55+
Issue8.log('render Sub ${value.raw}');
56+
return @hxx '<Div onclick=${onClick}>${value.raw == null ? null : value.raw.foo}</Div>';
57+
}
58+
}
59+
60+
class Div extends ReactComponent<{ onclick:()->Void, children:String }, {}> {
61+
override function render() return props.children;
62+
}
63+
64+
class Value<Raw, Result> implements Model {
65+
@:shared var raw:Raw;
66+
@:constant var parse:Raw->Outcome<Result, Error>;
67+
@:computed var parsed:Outcome<Result, Error> = parse(raw);
68+
public inline function sub<SubRaw, SubResult>(read:Raw->SubRaw, write:(Raw, SubRaw) -> Raw,
69+
parse:SubRaw->Outcome<SubResult, Error>):Value<SubRaw, SubResult> {
70+
return new Value({
71+
raw: observables.raw.transform({read: read, write: v -> write(raw, v)}),
72+
parse: parse,
73+
});
74+
}
75+
}

tests/ReactTestRenderer.hx

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,4 +8,5 @@ extern class ReactTestRenderer {
88

99
extern class ReactTestRoot {
1010
function findByProps(props:{}):Dynamic;
11+
function findByType(t:react.ReactType):Dynamic;
1112
}

tests/RunTests.hx

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,8 @@ class RunTests {
1111

1212
static function main() {
1313
Runner.run(TestBatch.make([
14-
new InjectTest()
14+
new InjectTest(),
15+
new Issue8(),
1516
])).handle(Runner.exit);
1617
}
1718
}

0 commit comments

Comments
 (0)