@@ -2,25 +2,29 @@ package coconut.diffing;
22
33import coconut .ui .Ref ;
44
5- @:using (coconut.diffing. Factory . FactoryTools )
6- interface Factory <Data , Native , Target : Native > {
7- final type : TypeId ;
8- function create (data : Data ): Target ;
9- function adopt (target : Native ): Null <Target >;
10- function hydrate (target : Target , data : Data ): Void ;
11- function update (target : Target , next : Data , prev : Data ): Void ;
12- }
5+ abstract class Factory <Data , Native , Target : Native > {
6+ public final type = new TypeId ();
7+
8+ public abstract function create (data : Data ): Target ;
9+ public abstract function update (target : Target , next : Data , prev : Data ): Void ;
10+
11+ /**
12+ Only used in hydration (by coconut.vdom). The currently encountered native node is passed to `adopt`.
13+ Return `null` if the wrong type of node is encountered.
14+ **/
15+ public function adopt (target : Native ): Null <Target > return null ;
16+ /**
17+ The actual implementation of the hydration (only used by coconut.vdom)
18+ **/
19+ public function hydrate (target : Target , data : Data ): Void {}
1320
14- class FactoryTools {
15- static public function vnode <Data , Native , Concrete : Native , RenderResult : VNode <Native >>(f : Factory <Data , Native , Concrete >, data : Data , ? key : Key , ? ref : Ref <Concrete >, ? children : Children <RenderResult >): VNode <Native >
16- return new VNative <Data , Native , Concrete >(f , data , key , ref , children );
21+ public function vnode <RenderResult : VNode <Native >>(data : Data , ? key : Key , ? ref : Ref <Target >, ? children : Children <RenderResult >): VNode <Native >
22+ return new VNative <Data , Native , Target >(this , data , key , ref , children );
1723}
1824
1925private typedef Dict <T > = Null <haxe. DynamicAccess <Null <T >>>;
2026
21- class Properties <Value , Native : {}, Target : Native > implements Factory <Dict <Value >, Native , Target > {
22-
23- public final type = new TypeId ();
27+ class Properties <Value , Native : {}, Target : Native > extends Factory <Dict <Value >, Native , Target > {
2428
2529 final construct : ()-> Target ;
2630 final apply : (target : Target , name : String , nu : Null <Value >, old : Null <Value >)-> Void ;
@@ -30,11 +34,6 @@ class Properties<Value, Native:{}, Target:Native> implements Factory<Dict<Value>
3034 this .apply = apply ;
3135 }
3236
33- public function adopt (target )
34- return null ;
35-
36- public function hydrate (target , data ) {}
37-
3837 public function create (data : Dict <Value >): Target {
3938 var ret = construct ();
4039 update (ret , data , null );
0 commit comments