-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcomponentization.html
More file actions
1041 lines (1014 loc) · 55.9 KB
/
componentization.html
File metadata and controls
1041 lines (1014 loc) · 55.9 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">
<meta name="description" content="">
<meta name="author" content="">
<title>Componentization | fuse X</title>
<link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/font-awesome/4.7.0/css/font-awesome.min.css" integrity="sha384-wvfXpqpZZVQGK6TAh5PVlGOfQNHSoD2xbE+QkPxCAFlNEevoEH3Sl0sibVcOQVnN" crossorigin="anonymous">
<link rel="stylesheet" href="https://fuse-x.com/style.css?1635266413">
<link rel="stylesheet" href="https://docs.fuse-x.com/prism.css?935">
<link rel="stylesheet" href="https://docs.fuse-x.com/site.css?939">
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/docsearch.js@2/dist/cdn/docsearch.min.css" />
<link rel="icon" href="https://fuse-x.com/favicon.ico?1602518038">
<link rel="shortcut icon" href="https://fuse-x.com/favicon.ico?1602518038">
<!-- Global site tag (gtag.js) - Google Analytics -->
<script async src="https://www.googletagmanager.com/gtag/js?id=UA-180445579-1"></script>
<script>
window.dataLayer = window.dataLayer || [];
function gtag(){dataLayer.push(arguments);}
gtag('js', new Date());
gtag('config', 'UA-180445579-1');
</script>
<link href="https://fonts.googleapis.com/css?family=Lato:400,500,600,700,900" rel="stylesheet">
<link rel="stylesheet" href="https://cdn.rawgit.com/afeld/bootstrap-toc/v1.0.1/dist/bootstrap-toc.min.css" />
</head>
<body data-spy="scroll" data-target="#toc" data-offset="73">
<header class="site-header sticky-top" role="banner">
<nav class="navbar navbar-expand-sm bg-dark navbar-dark">
<a class="navbar-brand" href="https://fuse-x.com/">
<img src="https://fuse-x.com/img/icon.png?1657530116" style="width: 32px; height: 32px" class="align-middle">
</a>
<button class="navbar-toggler" type="button" data-toggle="collapse" data-target="#navbarSupportedContent" aria-controls="navbarSupportedContent" aria-expanded="false" aria-label="Toggle navigation">
<span class="navbar-toggler-icon"></span>
</button>
<div class="collapse navbar-collapse" id="navbarSupportedContent">
<ul class="navbar-nav main-menu">
<li class="nav-item">
<a class="nav-link" href="https://fuse-x.com/">Home</a>
</li>
<li class="nav-item">
<a class="nav-link" href="https://fuse-x.com/download/">Download</a>
</li>
<li class="nav-item">
<a class="nav-link active" href="https://fuse-x.com/docs/">Documentation</a>
</li>
<li class="nav-item">
<a class="nav-link" href="https://fuse-x.com/examples/">Examples</a>
</li>
<li class="nav-item">
<a class="nav-link" href="https://fuse-x.com/community/">Community</a>
</li>
</ul>
</div>
</nav>
</header>
<div class="container-fluid">
<div class="row">
<div class="col-12 col-md-3 col-xl-2 order-2 order-md-1 bg-light sidebar">
<div class="sticky">
<div class="sticky-search">
<form id="search">
<input type="search" class="form-control" id="search-input" placeholder="Search..." aria-label="Search for..." autocomplete="off">
</form>
</div>
<ul class="list-unstyled outline-nav outline-nav-level-0 show">
<li>
<a href="https://docs.fuse-x.com/index.html" data-menu="index"><span>Fuse</span></a>
<ul class="list-unstyled outline-nav outline-nav-level-1 show">
<li>
<a href="#start" data-toggle="collapse"><span>Getting Started</span></a>
<ul id="start" class="list-unstyled outline-nav collapse outline-nav-level-2">
<li>
<a href="https://docs.fuse-x.com/basics/supported-platforms.html" data-menu="supported-platforms"><span>Supported platforms</span></a>
</li>
<li>
<a href="https://docs.fuse-x.com/basics/installation-and-quickstart.html" data-menu="installation-and-quickstart"><span>Installation and quickstart</span></a>
</li>
<li>
<a href="https://docs.fuse-x.com/basics/installation/setup-install-mac.html" data-menu="setup-install-mac"><span>macOS installation</span></a>
</li>
<li>
<a href="https://docs.fuse-x.com/basics/installation/setup-install-win.html" data-menu="setup-install-win"><span>Windows installation</span></a>
</li>
<li>
<a href="https://docs.fuse-x.com/basics/introduction-to-fuse.html" data-menu="introduction-to-fuse"><span>Introduction to Fuse</span></a>
</li>
<li>
<a href="https://docs.fuse-x.com/fuse-sdk/fuse-sdk.html" data-menu="fuse-sdk"><span>Introduction to Fuse SDK</span></a>
</li>
<li>
<a href="https://docs.fuse-x.com/fuse-studio/fuse-studio.html" data-menu="fuse-studio"><span>Introduction to Fuse X</span></a>
</li>
<li>
<a href="https://docs.fuse-x.com/basics/feature-overview.html" data-menu="feature-overview"><span>Feature overview</span></a>
</li>
</ul>
</li>
<li>
<a href="#tutorial" data-toggle="collapse"><span>Tutorial</span></a>
<ul id="tutorial" class="list-unstyled outline-nav collapse outline-nav-level-2">
<li>
<a href="https://docs.fuse-x.com/tutorial-models/tutorial.html" data-menu="tutorial"><span>Introduction</span></a>
</li>
<li>
<a href="https://docs.fuse-x.com/tutorial-models/edit-hike-view.html" data-menu="edit-hike-view"><span>Step 1: Edit Hike view</span></a>
</li>
<li>
<a href="https://docs.fuse-x.com/tutorial-models/multiple-hikes.html" data-menu="multiple-hikes"><span>Step 2: Multiple hikes</span></a>
</li>
<li>
<a href="https://docs.fuse-x.com/tutorial-models/splitting-up-components.html" data-menu="splitting-up-components"><span>Step 3: Splitting up components</span></a>
</li>
<li>
<a href="https://docs.fuse-x.com/tutorial-models/navigation-and-routing.html" data-menu="navigation-and-routing"><span>Step 4: Navigation and routing</span></a>
</li>
<li>
<a href="https://docs.fuse-x.com/tutorial-models/mock-backend.html" data-menu="mock-backend"><span>Step 5: Mocking our Backend</span></a>
</li>
<li>
<a href="https://docs.fuse-x.com/tutorial-models/look-and-feel.html" data-menu="look-and-feel"><span>Step 6: Tweaking the look/feel</span></a>
</li>
<li>
<a href="https://docs.fuse-x.com/tutorial-models/splash-screen.html" data-menu="splash-screen"><span>Step 7: Splash screen</span></a>
</li>
<li>
<a href="https://docs.fuse-x.com/tutorial-models/final-thoughts.html" data-menu="final-thoughts"><span>Step 8: Final thoughts</span></a>
</li>
</ul>
</li>
<li>
<a href="#development" data-toggle="collapse"><span>Development</span></a>
<ul id="development" class="list-unstyled outline-nav collapse outline-nav-level-2 show">
<li>
<a href="#ux_markup" data-toggle="collapse"><span>UX Markup</span></a>
<ul id="ux_markup" class="list-unstyled outline-nav collapse outline-nav-level-3 show">
<li>
<a href="https://docs.fuse-x.com/ux-markup/ux-markup.html" data-menu="ux-markup"><span>Introduction</span></a>
</li>
<li>
<a href="https://docs.fuse-x.com/componentization.html" data-menu="componentization" class="active"><span>Componentization</span></a>
</li>
<li>
<a href="https://docs.fuse-x.com/layout/responsive-layout.html" data-menu="responsive-layout"><span>Responsive Layout</span></a>
</li>
<li>
<a href="https://docs.fuse-x.com/layout/safe-layout.html" data-menu="safe-layout"><span>Safe Layout</span></a>
</li>
<li>
<a href="https://docs.fuse-x.com/declarative-animation.html" data-menu="declarative-animation"><span>Declarative animation</span></a>
</li>
<li>
<a href="https://docs.fuse-x.com/fuse-for-designers.html" data-menu="fuse-for-designers"><span>Fuse for designers</span></a>
</li>
<li>
<a href="https://docs.fuse-x.com/structuring-app-resources.html" data-menu="structuring-app-resources"><span>Structuring app resources</span></a>
</li>
<li>
<a href="https://docs.fuse-x.com/basics/preview-and-export.html" data-menu="preview-and-export"><span>Preview and export</span></a>
</li>
<li>
<a href="https://docs.fuse-x.com/ux-markup/literals.html" data-menu="literals"><span>Literals</span></a>
</li>
<li>
<a href="https://docs.fuse-x.com/ux-markup/expressions.html" data-menu="expressions"><span>Expressions</span></a>
</li>
<li>
<a href="https://docs.fuse-x.com/ux-markup/names.html" data-menu="names"><span>Names (ux:Name)</span></a>
</li>
<li>
<a href="https://docs.fuse-x.com/ux-markup/classes.html" data-menu="classes"><span>Classes (ux:Class)</span></a>
</li>
<li>
<a href="https://docs.fuse-x.com/ux-markup/dependencies.html" data-menu="dependencies"><span>Dependencies (ux:Dependency)</span></a>
</li>
<li>
<a href="https://docs.fuse-x.com/ux-markup/properties.html" data-menu="properties"><span>Properties (ux:Property)</span></a>
</li>
<li>
<a href="https://docs.fuse-x.com/ux-markup/resources.html" data-menu="resources"><span>Resources (ux:Key)</span></a>
</li>
<li>
<a href="https://docs.fuse-x.com/ux-markup/globals.html" data-menu="globals"><span>Globals (ux:Global)</span></a>
</li>
<li>
<a href="https://docs.fuse-x.com/ux-markup/templates.html" data-menu="templates"><span>Templates (ux:Template)</span></a>
</li>
<li>
<a href="https://docs.fuse-x.com/ux-markup/binding-and-auto-bind.html" data-menu="binding-and-auto-bind"><span>Binding (ux:Binding & ux:AutoBind)</span></a>
</li>
<li>
<a href="https://docs.fuse-x.com/testing/testing.html" data-menu="testing"><span>Testing (ux:Test)</span></a>
</li>
</ul>
</li>
<li>
<a href="#components" data-toggle="collapse"><span>Built-in Components</span></a>
<ul id="components" class="list-unstyled outline-nav collapse outline-nav-level-3">
<li>
<a href="#primitives" data-toggle="collapse"><span>Primitives</span></a>
<ul id="primitives" class="list-unstyled outline-nav collapse outline-nav-level-4">
<li>
<a href="https://docs.fuse-x.com/primitives/primitives.html" data-menu="primitives"><span>Introduction</span></a>
</li>
<li>
<a href="https://docs.fuse-x.com/fuse/controls/text.html" data-menu="text"><span>Text</span></a>
</li>
<li>
<a href="https://docs.fuse-x.com/fuse/controls/rectangle.html" data-menu="rectangle"><span>Rectangle</span></a>
</li>
<li>
<a href="https://docs.fuse-x.com/fuse/controls/circle.html" data-menu="circle"><span>Circle</span></a>
</li>
<li>
<a href="https://docs.fuse-x.com/fuse/controls/curve.html" data-menu="curve"><span>Curve</span></a>
<ul class="list-unstyled outline-nav collapse outline-nav-level-5">
<li>
<a href="https://docs.fuse-x.com/fuse/controls/curvepoint.html" data-menu="curvepoint"><span>CurvePoint</span></a>
</li>
</ul>
</li>
<li>
<a href="https://docs.fuse-x.com/fuse/controls/path.html" data-menu="path"><span>Path</span></a>
</li>
<li>
<a href="https://docs.fuse-x.com/fuse/controls/image.html" data-menu="image"><span>Image</span></a>
</li>
<li>
<a href="https://docs.fuse-x.com/fuse/controls/video.html" data-menu="video"><span>Video</span></a>
</li>
<li>
<a href="https://docs.fuse-x.com/fuse/playsound.html" data-menu="playsound"><span>Sound</span></a>
</li>
</ul>
</li>
<li>
<a href="#controls" data-toggle="collapse"><span>Controls</span></a>
<ul id="controls" class="list-unstyled outline-nav collapse outline-nav-level-4">
<li>
<a href="https://docs.fuse-x.com/fuse/controls/control.html" data-menu="control"><span>Introduction</span></a>
</li>
<li>
<a href="https://docs.fuse-x.com/fuse/controls/button.html" data-menu="button"><span>Button</span></a>
</li>
<li>
<a href="https://docs.fuse-x.com/fuse/controls/textinput.html" data-menu="textinput"><span>TextInput</span></a>
</li>
<li>
<a href="https://docs.fuse-x.com/fuse/controls/textview.html" data-menu="textview"><span>TextView</span></a>
</li>
<li>
<a href="https://docs.fuse-x.com/fuse/controls/slider.html" data-menu="slider"><span>Slider</span></a>
</li>
<li>
<a href="https://docs.fuse-x.com/fuse/controls/switch.html" data-menu="switch"><span>Switch</span></a>
</li>
<li>
<a href="https://docs.fuse-x.com/fuse/controls/cameraviewbase.html" data-menu="cameraviewbase"><span>CameraView</span></a>
</li>
<li>
<a href="https://docs.fuse-x.com/fuse/controls/mapview.html" data-menu="mapview"><span>MapView</span></a>
</li>
<li>
<a href="https://docs.fuse-x.com/fuse/controls/webview.html" data-menu="webview"><span>WebView</span></a>
</li>
<li>
<a href="https://docs.fuse-x.com/fuse/controls/nativeviewhost.html" data-menu="nativeviewhost"><span>NativeViewHost</span></a>
</li>
<li>
<a href="https://docs.fuse-x.com/fuse/controls/graphicsview.html" data-menu="graphicsview"><span>GraphicsView</span></a>
</li>
</ul>
</li>
<li>
<a href="#layouts" data-toggle="collapse"><span>Layouts</span></a>
<ul id="layouts" class="list-unstyled outline-nav collapse outline-nav-level-4">
<li>
<a href="https://docs.fuse-x.com/layout/layout.html" data-menu="layout"><span>Introduction</span></a>
</li>
<li>
<a href="https://docs.fuse-x.com/fuse/elements/element.html" data-menu="element"><span>Element</span></a>
</li>
<li>
<a href="https://docs.fuse-x.com/fuse/controls/panel.html" data-menu="panel"><span>Panel</span></a>
</li>
<li>
<a href="https://docs.fuse-x.com/fuse/controls/stackpanel.html" data-menu="stackpanel"><span>StackPanel</span></a>
</li>
<li>
<a href="https://docs.fuse-x.com/fuse/controls/dockpanel.html" data-menu="dockpanel"><span>DockPanel</span></a>
</li>
<li>
<a href="https://docs.fuse-x.com/fuse/controls/grid.html" data-menu="grid"><span>Grid</span></a>
</li>
<li>
<a href="https://docs.fuse-x.com/fuse/controls/wrappanel.html" data-menu="wrappanel"><span>WrapPanel</span></a>
</li>
<li>
<a href="https://docs.fuse-x.com/fuse/layouts/columnlayout.html" data-menu="columnlayout"><span>ColumnLayout</span></a>
</li>
<li>
<a href="https://docs.fuse-x.com/fuse/layouts/circlelayout.html" data-menu="circlelayout"><span>CircleLayout</span></a>
</li>
<li>
<a href="https://docs.fuse-x.com/fuse/controls/scrollview.html" data-menu="scrollview"><span>ScrollView</span></a>
</li>
</ul>
</li>
<li>
<a href="#navigation" data-toggle="collapse"><span>Navigation</span></a>
<ul id="navigation" class="list-unstyled outline-nav collapse outline-nav-level-4">
<li>
<a href="https://docs.fuse-x.com/navigation/navigation.html" data-menu="navigation"><span>Introduction</span></a>
</li>
<li>
<a href="https://docs.fuse-x.com/fuse/controls/page.html" data-menu="page"><span>Page</span></a>
</li>
<li>
<a href="https://docs.fuse-x.com/fuse/controls/pagecontrol.html" data-menu="pagecontrol"><span>PageControl</span></a>
</li>
<li>
<a href="https://docs.fuse-x.com/fuse/navigation/router.html" data-menu="router"><span>Router</span></a>
</li>
<li>
<a href="https://docs.fuse-x.com/fuse/controls/navigator.html" data-menu="navigator"><span>Navigator</span></a>
</li>
<li>
<a href="https://docs.fuse-x.com/fuse/triggers/transition.html" data-menu="transition"><span>Transitions</span></a>
</li>
</ul>
</li>
<li>
<a href="#alive" data-toggle="collapse"><span>Alive UX Kit</span></a>
<ul id="alive" class="list-unstyled outline-nav collapse outline-nav-level-4">
<li>
<a href="https://docs.fuse-x.com/alive/alive.html" data-menu="alive"><span>Introduction</span></a>
</li>
<li>
<a href="https://docs.fuse-x.com/alive.html" data-menu="alive"><span>Components</span></a>
</li>
<li>
<a href="https://docs.fuse-x.com/alive/themes.html" data-menu="themes"><span>Themes</span></a>
</li>
</ul>
</li>
<li>
<a href="#charting" data-toggle="collapse"><span>Charting</span></a>
<ul id="charting" class="list-unstyled outline-nav collapse outline-nav-level-4">
<li>
<a href="https://docs.fuse-x.com/charting/charting.html" data-menu="charting"><span>Introduction</span></a>
</li>
<li>
<a href="https://docs.fuse-x.com/fuse/charting/plot.html" data-menu="plot"><span>Plot</span></a>
</li>
<li>
<a href="https://docs.fuse-x.com/fuse/charting/dataseries.html" data-menu="dataseries"><span>DataSeries</span></a>
</li>
<li>
<a href="https://docs.fuse-x.com/fuse/charting/plotaxis.html" data-menu="plotaxis"><span>PlotAxis</span></a>
</li>
<li>
<a href="https://docs.fuse-x.com/fuse/charting/plotdata.html" data-menu="plotdata"><span>PlotData</span></a>
</li>
<li>
<a href="https://docs.fuse-x.com/fuse/charting/plotpoint.html" data-menu="plotpoint"><span>PlotPoint</span></a>
</li>
<li>
<a href="https://docs.fuse-x.com/fuse/charting/plotbar.html" data-menu="plotbar"><span>PlotBar</span></a>
</li>
<li>
<a href="https://docs.fuse-x.com/fuse/charting/plotcurvepoint.html" data-menu="plotcurvepoint"><span>PlotCurvePoint</span></a>
</li>
</ul>
</li>
</ul>
</li>
<li>
<a href="#animation" data-toggle="collapse"><span>Triggers & Animation</span></a>
<ul id="animation" class="list-unstyled outline-nav collapse outline-nav-level-3">
<li>
<a href="https://docs.fuse-x.com/fuse/triggers/trigger.html" data-menu="trigger"><span>Introduction</span></a>
</li>
<li>
<a href="https://docs.fuse-x.com/fuse/transform.html" data-menu="transform"><span>Transforms</span></a>
</li>
<li>
<a href="https://docs.fuse-x.com/fuse/gestures/transformgesture.html" data-menu="transformgesture"><span>Gestures</span></a>
</li>
<li>
<a href="https://docs.fuse-x.com/fuse/animations/animator.html" data-menu="animator"><span>Animators</span></a>
</li>
<li>
<a href="https://docs.fuse-x.com/fuse/triggers/timeline.html" data-menu="timeline"><span>Timeline</span></a>
</li>
<li>
<a href="https://docs.fuse-x.com/fuse/triggers/actions/triggeraction.html" data-menu="triggeraction"><span>Actions</span></a>
</li>
<li>
<a href="https://docs.fuse-x.com/fuse/selection/selection.html" data-menu="selection"><span>Selection</span></a>
</li>
<li>
<a href="https://docs.fuse-x.com/fuse/triggers/stategroup.html" data-menu="stategroup"><span>StateGroups</span></a>
</li>
<li>
<a href="https://docs.fuse-x.com/fuse/controls/multilayoutpanel.html" data-menu="multilayoutpanel"><span>MultiLayoutPanel</span></a>
</li>
<li>
<a href="https://docs.fuse-x.com/fuse/triggers/busy.html" data-menu="busy"><span>Busy</span></a>
</li>
</ul>
</li>
<li>
<a href="#effects" data-toggle="collapse"><span>Effects</span></a>
<ul id="effects" class="list-unstyled outline-nav collapse outline-nav-level-3">
<li>
<a href="https://docs.fuse-x.com/effects/effects.html" data-menu="effects"><span>Introduction</span></a>
</li>
<li>
<a href="https://docs.fuse-x.com/fuse/effects/dropshadow.html" data-menu="dropshadow"><span>DropShadow</span></a>
</li>
<li>
<a href="https://docs.fuse-x.com/fuse/effects/blur.html" data-menu="blur"><span>Blur</span></a>
</li>
<li>
<a href="https://docs.fuse-x.com/fuse/effects/halftone.html" data-menu="halftone"><span>Halftone</span></a>
</li>
</ul>
</li>
<li>
<a href="#resources" data-toggle="collapse"><span>Resources</span></a>
<ul id="resources" class="list-unstyled outline-nav collapse outline-nav-level-3">
<li>
<a href="https://docs.fuse-x.com/uno/ux/resource.html" data-menu="resource"><span>Introduction</span></a>
</li>
<li>
<a href="https://docs.fuse-x.com/fuse/font.html" data-menu="font"><span>Fonts</span></a>
</li>
<li>
<a href="https://docs.fuse-x.com/fuse/resources/imagesource.html" data-menu="imagesource"><span>Image sources</span></a>
</li>
<li>
<a href="https://docs.fuse-x.com/assets/bundle.html" data-menu="bundle"><span>Bundled files</span></a>
</li>
<li>
<a href="https://docs.fuse-x.com/assets/sketch-import.html" data-menu="sketch-import"><span>Import from Sketch</span></a>
</li>
<li>
<a href="https://docs.fuse-x.com/assets/sketch-symbol-import.html" data-menu="sketch-symbol-import"><span>Sketch symbols (Beta)</span></a>
</li>
<li>
<a href="https://docs.fuse-x.com/assets/iconfont-import.html" data-menu="iconfont-import"><span>Import icon fonts</span></a>
</li>
</ul>
</li>
<li>
<a href="#scripting" data-toggle="collapse"><span>Scripting & Data Binding</span></a>
<ul id="scripting" class="list-unstyled outline-nav collapse outline-nav-level-3">
<li>
<a href="https://docs.fuse-x.com/scripting/scripting.html" data-menu="scripting"><span>Introduction</span></a>
</li>
<li>
<a href="https://docs.fuse-x.com/fuse/reactive/javascript.html" data-menu="javascript"><span>FuseJS</span></a>
</li>
<li>
<a href="https://docs.fuse-x.com/fusejs-beta/fusejs.html" data-menu="fusejs"><span>Model API</span></a>
</li>
<li>
<a href="#fusejs" data-toggle="collapse"><span>FuseJS (JavaScript) APIs</span></a>
<ul id="fusejs" class="list-unstyled outline-nav collapse outline-nav-level-4">
<li>
<a href="https://docs.fuse-x.com/fusejs/polyfills.html" data-menu="polyfills"><span>Polyfills</span></a>
</li>
<li>
<a href="https://docs.fuse-x.com/fusejs/eventemitter.html" data-menu="eventemitter"><span>EventEmitter</span></a>
</li>
<li>
<a href="https://docs.fuse-x.com/fuse/filesystem/filesystemmodule.html" data-menu="filesystemmodule"><span>FileSystem</span></a>
</li>
<li>
<a href="https://docs.fuse-x.com/fuse/storage/storagemodule.html" data-menu="storagemodule"><span>Storage</span></a>
</li>
<li>
<a href="https://docs.fuse-x.com/fusejs/bundle.html" data-menu="bundle"><span>Bundle</span></a>
</li>
<li>
<a href="https://docs.fuse-x.com/fusejs/lifecycle.html" data-menu="lifecycle"><span>Lifecycle</span></a>
</li>
<li>
<a href="https://docs.fuse-x.com/fuse/reactive/fusejs/interapp.html" data-menu="interapp"><span>InterApp</span></a>
</li>
<li>
<a href="https://docs.fuse-x.com/fuse/share/sharemodule.html" data-menu="sharemodule"><span>Share</span></a>
</li>
<li>
<a href="https://docs.fuse-x.com/fusejs/http.html" data-menu="http"><span>HTTP</span></a>
</li>
<li>
<a href="https://docs.fuse-x.com/backend/rest-apis.html" data-menu="rest-apis"><span>Working with REST APIs</span></a>
</li>
<li>
<a href="https://docs.fuse-x.com/fusejs/environment.html" data-menu="environment"><span>Environment</span></a>
</li>
<li>
<a href="https://docs.fuse-x.com/fuse/reactive/fusejs/phone.html" data-menu="phone"><span>Phone</span></a>
</li>
<li>
<a href="https://docs.fuse-x.com/fuse/camera/camera.html" data-menu="camera"><span>Camera</span></a>
</li>
<li>
<a href="https://docs.fuse-x.com/fuse/cameraroll/cameraroll.html" data-menu="cameraroll"><span>CameraRoll</span></a>
</li>
<li>
<a href="https://docs.fuse-x.com/fuse/vibration/vibrationmodule.html" data-menu="vibrationmodule"><span>Vibration</span></a>
</li>
<li>
<a href="https://docs.fuse-x.com/fuse/geolocation/geolocation.html" data-menu="geolocation"><span>GeoLocation</span></a>
</li>
<li>
<a href="https://docs.fuse-x.com/fuse/pushnotifications/push.html" data-menu="push"><span>Push notifications</span></a>
</li>
<li>
<a href="https://docs.fuse-x.com/fuse/localnotifications/localnotify.html" data-menu="localnotify"><span>Local notifications</span></a>
</li>
<li>
<a href="https://docs.fuse-x.com/fuse/sensor/sensormodule.html" data-menu="sensormodule"><span>Sensors</span></a>
</li>
<li>
<a href="https://docs.fuse-x.com/fusejs/base64.html" data-menu="base64"><span>Base64</span></a>
</li>
<li>
<a href="https://docs.fuse-x.com/fuse/reactive/fusejs/timermodule.html" data-menu="timermodule"><span>Timer</span></a>
</li>
<li>
<a href="https://docs.fuse-x.com/fuse/imagetools/imagetools.html" data-menu="imagetools"><span>ImageTools</span></a>
</li>
<li>
<a href="https://docs.fuse-x.com/fusejs/third-party-modules.html" data-menu="third-party-modules"><span>Third-party modules</span></a>
</li>
</ul>
</li>
<li>
<a href="#observable" data-toggle="collapse"><span>Observables API</span></a>
<ul id="observable" class="list-unstyled outline-nav collapse outline-nav-level-4">
<li>
<a href="https://docs.fuse-x.com/fusejs/observable.html" data-menu="observable"><span>Introduction</span></a>
</li>
<li>
<a href="https://docs.fuse-x.com/fusejs/observable-api.html" data-menu="observable-api"><span>Full API reference</span></a>
</li>
<li>
<a href="https://docs.fuse-x.com/fusejs/observable-patterns.html" data-menu="observable-patterns"><span>Patterns</span></a>
</li>
</ul>
</li>
<li>
<a href="https://docs.fuse-x.com/scripting/debugging.html" data-menu="debugging"><span>Debugging</span></a>
</li>
<li>
<a href="#databinding" data-toggle="collapse"><span>Data Binding</span></a>
<ul id="databinding" class="list-unstyled outline-nav collapse outline-nav-level-4">
<li>
<a href="https://docs.fuse-x.com/fuse/reactive/databinding.html" data-menu="databinding"><span>Introduction</span></a>
</li>
<li>
<a href="https://docs.fuse-x.com/fuse/reactive/each.html" data-menu="each"><span>Each</span></a>
</li>
<li>
<a href="https://docs.fuse-x.com/fuse/reactive/with.html" data-menu="with"><span>With</span></a>
</li>
<li>
<a href="https://docs.fuse-x.com/fuse/reactive/match.html" data-menu="match"><span>Match</span></a>
<ul class="list-unstyled outline-nav collapse outline-nav-level-5">
<li>
<a href="https://docs.fuse-x.com/fuse/reactive/case.html" data-menu="case"><span>Case</span></a>
</li>
</ul>
</li>
</ul>
</li>
</ul>
</li>
</ul>
</li>
<li>
<a href="#integration" data-toggle="collapse"><span>Platform Integration</span></a>
<ul id="integration" class="list-unstyled outline-nav collapse outline-nav-level-2">
<li>
<a href="https://docs.fuse-x.com/xcode-and-android-studio-integration/tutorial.html" data-menu="tutorial"><span>Add Fuse to existing App</span></a>
</li>
<li>
<a href="https://docs.fuse-x.com/native-interop/native-interop.html" data-menu="native-interop"><span>Native interop (Uno)</span></a>
</li>
<li>
<a href="https://docs.fuse-x.com/native-interop/native-ux-components.html" data-menu="native-ux-components"><span>Native UX components</span></a>
</li>
<li>
<a href="https://docs.fuse-x.com/native-interop/native-js-modules.html" data-menu="native-js-modules"><span>Native JS modules</span></a>
</li>
<li>
<a href="https://docs.fuse-x.com/native-interop/foreign-code.html" data-menu="foreign-code"><span>Foreign code</span></a>
</li>
<li>
<a href="https://docs.fuse-x.com/native-interop/using-third-party-sdks.html" data-menu="using-third-party-sdks"><span>Using 3rd party SDKs</span></a>
</li>
<li>
<a href="https://docs.fuse-x.com/native-interop/facebook-login.html" data-menu="facebook-login"><span>Example Facebook login using foreign code</span></a>
</li>
<li>
<a href="https://docs.fuse-x.com/native-interop/build-settings.html" data-menu="build-settings"><span>Build settings</span></a>
</li>
<li>
<a href="#integration_android" data-toggle="collapse"><span>Android Specifics</span></a>
<ul id="integration_android" class="list-unstyled outline-nav collapse outline-nav-level-3">
<li>
<a href="https://docs.fuse-x.com/native-interop/gradle-support.html" data-menu="gradle-support"><span>Gradle Support</span></a>
</li>
<li>
<a href="https://docs.fuse-x.com/native-interop/android-permissions.html" data-menu="android-permissions"><span>Android permissions</span></a>
</li>
<li>
<a href="https://docs.fuse-x.com/unolibs/activity-utils.html" data-menu="activity-utils"><span>Activity utils</span></a>
</li>
<li>
<a href="https://docs.fuse-x.com/native-interop/android-start-activity.html" data-menu="android-start-activity"><span>Starting an Android Activity</span></a>
</li>
</ul>
</li>
<li>
<a href="#integration_ios" data-toggle="collapse"><span>IOS Specifics</span></a>
<ul id="integration_ios" class="list-unstyled outline-nav collapse outline-nav-level-3">
<li>
<a href="https://docs.fuse-x.com/native-interop/ios-capabilities.html" data-menu="ios-capabilities"><span>iOS Capabilities</span></a>
</li>
</ul>
</li>
</ul>
</li>
<li>
<a href="#technical-corner" data-toggle="collapse"><span>Technical corner</span></a>
<ul id="technical-corner" class="list-unstyled outline-nav collapse outline-nav-level-2">
<li>
<a href="https://docs.fuse-x.com/technical-corner/technical-corner.html" data-menu="technical-corner"><span>Introduction</span></a>
</li>
<li>
<a href="https://docs.fuse-x.com/technical-corner/fuse-protocol.html" data-menu="fuse-protocol"><span>Fuse plugin API</span></a>
</li>
<li>
<a href="https://docs.fuse-x.com/preview-and-export/preview-details.html" data-menu="preview-details"><span>How preview works</span></a>
</li>
<li>
<a href="https://docs.fuse-x.com/technical-corner/uxl-handbook.html" data-menu="uxl-handbook"><span>UXL handbook</span></a>
</li>
</ul>
</li>
<li>
<a href="#references" data-toggle="collapse"><span>References</span></a>
<ul id="references" class="list-unstyled outline-nav collapse outline-nav-level-2">
<li>
<a href="https://docs.fuse-x.com/basics/uno-projects.html" data-menu="uno-projects"><span>Project Reference (.unoproj file)</span></a>
</li>
<li>
<a href="https://docs.fuse-x.com/full-ux-class-reference.html" data-menu="full-ux-class-reference"><span>Full UX Class Reference</span></a>
</li>
<li>
<a href="https://docs.fuse-x.com/root-ns.html" data-menu="index"><span>Uno Class Reference</span></a>
</li>
<li>
<a href="https://docs.fuse-x.com/basics/faq.html" data-menu="faq"><span>FAQ</span></a>
</li>
<li>
<a href="https://docs.fuse-x.com/packages.html" data-menu="packages"><span>Community Packages</span></a>
</li>
</ul>
</li>
</ul>
</li>
</ul>
</div>
</div>
<div role="main" class="col-12 col-md-9 col-xl-10 order-1 order-md-2 px-4 main">
<div class="row">
<div class="col-12 col-sm-12 col-md-9 col-xl-9 main-content">
<h1 id="componentization">Componentization</h1>
<p>This article covers best practices and workflow around creating components in Fuse.</p>
<h2 id="components-and-reusability">Components and reusability</h2>
<p>UX Markup is a composable declarative language where existing components can easily be combined into new, more complex components. Componentization is an important part of Fuse, and central to achieving good code structure.</p>
<h2 id="how-to-create-components">How to create components</h2>
<p>A component is defined using the <code>ux:Class</code> attribute. This turns the object it is on into a <em>class definition</em>, meaning we can reuse that piece of UX in as many places as we want. A class definition also <em>inherits</em> all the properties of the class it is created from (sometimes called its <em>parent class</em> or <em>super class</em>). When we create an object from a class definition, we say that we are <em>creating an instance</em> of that class. The following example defines a class called <code>MyButton</code> which inherits from <code>Panel</code> and contains a <code>Text</code> object.</p>
<pre><code class="language-xml"> ___________________ parent class
/ ________ class name
v v
<Panel ux:Class="MyButton" Color="#09d" Margin="4">
<Text Value="Button text" Alignment="Center" Margin="20,10" Color="#fff" />
</Panel></code></pre>
<p>It can then be used anywhere, like so:</p>
<pre><code class="language-xml"><StackPanel>
<MyButton />
<MyButton />
<MyButton />
</StackPanel></code></pre>
<p>Take a look at the <a href="ux-markup/classes.html">ux:Class documentation</a> for more details about <code>ux:Class</code>.</p>
<h3 id="what-do-we-mean-by-inheritance">What do we mean by inheritance</h3>
<p>When we say that <code>MyButton</code> <em>inherits</em> from <code>Panel</code>, what we really mean is that <code>MyButton</code> will get all the same properties as <code>Panel</code>, as well as any new properties we define ourselves. That means that a class without any extra children or properties (custom properties are covered in the next section) added acts as exactly the same as its parent class:</p>
<pre><code class="language-xml"><Panel ux:Class="NotSoSpecialPanel" />
<Panel />
<NotSoSpecialPanel /></code></pre>
<p>In this case, <code>Panel</code> and <code>NotSoSpecialPanel</code> behave exactly the same.</p>
<h3 id="defining-properties">Defining properties</h3>
<p>In many cases, like with our custom button, we want to create an interface to our component that allows us to specify various properties on a per instance basis. For our custom button for example, we want to be able to specify a different text for each instance:</p>
<pre><code class="language-xml"><MyButton Text="Custom button text" /></code></pre>
<p>The <code>ux:Property</code> attribute allows us to send data to our component, give default values and even animate it:</p>
<pre><code class="language-xml"><Panel ux:Class="MyButton" Color="#09d" ButtonText="Default text" Margin="4">
<string ux:Property="ButtonText" />
<Text Value="{ReadProperty ButtonText}" Alignment="Center" Margin="20,10" Color="#fff" />
</Panel></code></pre>
<pre><code class="language-xml"><StackPanel>
<MyButton ButtonText="First" />
<MyButton ButtonText="Second" />
<MyButton ButtonText="Last" />
</StackPanel></code></pre>
<p>Take a look at the <a href="ux-markup/properties.html">ux:Property documentation</a> for more details about creating properties.</p>
<h3 id="specifying-dependencies">Specifying dependencies</h3>
<p>In some cases, our components cannot work alone and need a way to express that they depend on some other part of our UX defined outside of our component. This could be to animate it or trigger an event. A very common use case is needing to share a common <code>Router</code> instance among several pages. The way this use case is different from our use of ux:Property is that we <strong>require</strong> our component to get a <code>Router</code> when it is instantiated. This way, from our components perspective, it <em>always</em> has a <code>Router</code> available. For this we use the <code>ux:Dependency</code> attribute:</p>
<pre><code class="language-xml"><Router ux:Dependency="router" /></code></pre>
<p>If we try to instantiate our component without specifying the <code>router</code> dependency we will get a UX compilation error, since this component cannot function without a <code>Router</code>. Unlike properties, dependencies cannot have default values.</p>
<p>From within the class definition, dependencies can be used exactly in the same way as if they were defined with the <code>ux:Name</code> attribute:</p>
<pre><code class="language-xml"><WhileTrue ux:Dependency="myTrigger" />
<WhileTrue ux:Name="myTrigger" /></code></pre>
<p>Both the <code>WhileTrue</code> declared as a dependency and the one declared with <code>ux:Name</code> can be referenced directly using the name <code>myTrigger</code>. Therefore, we cannot use the same identifier for a <code>ux:Dependency</code> and a <code>ux:Name</code>.</p>
<p>The following example shows how we can use <code>ux:Dependency</code> to toggle the state of a <code>WhileTrue</code> defined outside the class definition.</p>
<pre><code class="language-xml"><Panel ux:Class="DependentPanel" Color="Blue">
<WhileTrue ux:Dependency="aTrigger" />
<Clicked>
<Toggle Target="aTrigger" />
</Clicked>
</Panel>
<WhileTrue ux:Name="showSomething">
<Text Value="The panel was clicked" Color="White" Alignment="Center" />
</WhileTrue>
<DependentPanel aTrigger="showSomething" /></code></pre>
<p>Take a look at the <a href="ux-markup/dependencies.html">ux:Dependency documentation</a> for more details.</p>
<h4 id="inheriting-dependencies">Inheriting dependencies</h4>
<p>Dependencies are not forwarded when you subclass. Therefore, you have to manually forward them to the baseclass you are sublcassing:</p>
<pre><code class="language-xml"><Page ux:Class="A">
<Router ux:Dependency="router" />
</Page>
<A ux:Class="B">
<Router ux:Dependency="router" ux:Binding="router" />
</A></code></pre>
<p>You can find more details about the <code>ux:Binding</code> attribute <a href="ux-markup/binding-and-auto-bind.html#ux-binding">here</a>.</p>
<h3 id="inner-logic-using-javascript">Inner logic using JavaScript</h3>
<p>Components can contain custom business logic using the <code>JavaScript</code> tag. Here we can define local state as well as functions that act upon dependencies or other components. The following component takes a <code>Router</code> as a dependency, and uses it through JavaScript.</p>
<pre><code class="language-xml"><Panel ux:Class="MyClass">
<Router ux:Dependency="router" />
<JavaScript>
function goBack() {
router.goBack();
}
module.exports = {
doSomething: doSomething
};
</JavaScript>
<Button Text="Go Back" Clicked="{goBack}" />
</Panel></code></pre>
<h2 id="custom-events-userevent">Custom Events (UserEvent)</h2>
<p>There are many cases where we want our component to pass messages to the outside world.
We can use <code>UserEvent</code> for exactly this, which allows us to raise and handle events in both UX and JavaScript.</p>
<p>We put a <code>UserEvent</code> at the root of our component class to indicate that it can raise a particular event.
Where we place our <code>UserEvent</code> is important, since only the node it is attached to and its children can raise or handle it.</p>
<pre><code class="language-xml"><Panel ux:Class="MyComponent">
<UserEvent ux:Name="myEvent" />
</Panel></code></pre>
<p>This creates an event named <code>myEvent</code>.</p>
<p>We can now use <code>RaiseUserEvent</code> to raise the event from UX.</p>
<pre><code class="language-xml"><Clicked>
<RaiseUserEvent EventName="myEvent" />
</Clicked></code></pre>
<p>When we instantiate our component, we can respond to its events using the <code>OnUserEvent</code> trigger.</p>
<pre><code class="language-xml"><MyComponent>
<OnUserEvent EventName="myEvent">
... animations & actions ...
</OnUserEvent>
</MyComponent></code></pre>
<p>We recommend subclassing <code>OnUserEvent</code> instead of using it directly and setting its <code>EventName</code> each time:</p>
<pre><code class="language-xml"><Panel ux:Class="MyComponent">
<UserEvent ux:Name="myEvent" />
<OnUserEvent ux:Class="OnMyEvent" EventName="myEvent" />
</Panel>
<MyComponent>
<OnMyEvent>
... animations & actions ...
</OnMyEvent>
</MyComponent></code></pre>
<p>Note that <code>OnMyEvent</code> will only be usable inside <code>MyComponent</code>.</p>
<p>Check out the full <a href="ux-markup/user-events.html">documentation on the user event API</a> for more details.</p>
<h2 id="when-to-create-components">When to create components</h2>
<p>Since turning a piece of UX markup into a reusable component is often as simple as just adding the <code>ux:Class</code> attribute, we tend to componentize often. The challenge is not so much to understand when there is an opportunity for componentization, but to understand which components to make. When splitting up a complex piece of UX into reusable parts, we need to decide which parts should depend on each other, and at what abstraction level we want them to be defined. We will take a closer look at that question in the following sections.</p>
<h3 id="ux-class-workflow">ux:Class workflow</h3>
<p>Since componentization in Fuse is so quick, a common workflow when writing UX is to first write everything "in-line" without caring about components at all. We only componentize after we have found a structure we want to move forward with. The reason for why this approach is so valuable is that it avoids the potential pitfalls of prematurely abstracting code. This way, we can let all the reusable components naturally appear before we decide to abstract and assign class names.</p>
<h3 id="recognizing-component-boundaries">Recognizing component boundaries</h3>
<p>Making Fuse components is sometimes the art of determining effective component boundaries. The following example illustrates a case where there are several ways we might componentize:</p>
<pre><code class="language-xml"><StackPanel Margin="10" Padding="10" Color="#eee" ItemSpacing="8">
<Circle ux:Name="status" Width="40" Height="40" Color="Gray" />
<Grid ColumnCount="2" CellSpacing="8">
<Panel>
<Text Value="On" Alignment="Center" Margin="8" Color="White" />
<Clicked>
<Set status.Color="Green" />
</Clicked>
<Rectangle CornerRadius="3" Color="#0af" />
</Panel>
<Panel>
<Text Value="Off" Alignment="Center" Margin="8" Color="White" />
<Clicked>
<Set status.Color="Red" />
</Clicked>
<Rectangle CornerRadius="3" Color="#0af" />
</Panel>
</Grid>
</StackPanel></code></pre>
<p><img src="media/componentization/onoff_all_3.png" alt="component_boundary_example"></p>
<p>This is a <code>Panel</code> with a colored <code>Circle</code>, and two custom buttons that change its color. We already have several options for how to split this up:</p>
<p><strong>Everything as one component:</strong></p>
<pre><code class="language-xml"><StackPanel ux:Class="StatusPanel" ...>
...
</StackPanel></code></pre>
<p><strong>Or we can componentize the two buttons:</strong></p>
<pre><code class="language-xml"><StackPanel Margin="10" Padding="10" Color="#eee" ItemSpacing="8">
<Circle ux:Name="status" Width="40" Height="40" Color="Gray" />
<OnOffButtons />
</StackPanel></code></pre>
<pre><code class="language-xml"><Grid ux:Class="OnOffButtons" ColumnCount="2" CellSpacing="8">
<Circle ux:Dependency="status" />
<Panel>
<Text Value="On" Alignment="Center" Margin="8" Color="White" />
<Clicked>
<Set status.Color="Green" />
</Clicked>
<Rectangle CornerRadius="3" Color="#0af" />
</Panel>
<Panel>
<Text Value="Off" Alignment="Center" Margin="8" Color="White" />
<Clicked>
<Set status.Color="Red" />
</Clicked>
<Rectangle CornerRadius="3" Color="#0af" />
</Panel>
</Grid></code></pre>
<p>At this point we can see that there is a dependency between the inner workings of the <code>OnOffButtons</code> class and the "status" circle. We might be tempted to call this a dependency from <code>OnOffButtons</code> to a <code>Circle</code>, and declare that using <code>ux:Dependency</code> as we have done in the example above.</p>
<p>This is however a good time to consider whether we have discovered an actual component dependency, or whether this is just a shared view state.</p>
<p>In most cases, it is preferable to have components be as independent as possible. In the example above, we would like to split our components up in a way such that the <code>OnOffButtons</code> component can be used in other situations as well; not only to toggle the color of a <code>Circle</code>.</p>
<p>Let's let these two components share state using <code>JavaScript</code> instead:</p>
<pre><code class="language-xml"><Grid ux:Class="OnOffButtons" ColumnCount="2">
<Panel Clicked="{turnOn}">
<Text Value="On" Alignment="Center" Margin="8" Color="White" />
<Rectangle CornerRadius="3" Color="#0af" />
</Panel>
<Panel Clicked="{turnOff}">
<Text Value="Off" Alignment="Center" Margin="8" Color="White" />
<Rectangle CornerRadius="3" Color="#0af" />
</Panel>
</Grid>
<JavaScript>
var Observable = require("FuseJS/Observable");
var isOn = Observable(false);
function turnOn() { isOn.value = true; }
function turnOff() { isOn.value = false; }
module.exports = {
isOn: isOn,
turnOn: turnOn,
turnOff: turnOff
};
</JavaScript>
<StackPanel Margin="10" Padding="10" Color="#eee" ItemSpacing="8">
<Circle ux:Name="status" Width="40" Height="40" Color="Gray" />
<WhileTrue Value="{isOn}">
<Change status.Color="Green" />
</WhileTrue>
<WhileFalse Value="{isOn}">
<Change status.Color="Red" />
</WhileFalse>
</StatusCircle>
<OnOffButtons />
</StackPanel></code></pre>
<p>This time, our two components are independent of each other. They are, however, not independent of the view model (the <code>JavaScript</code> tag). Notice that the <code>OnOffButtons</code> component now has data-bindings that reach outside the component itself. While this works fine, and can be very useful, it can reduce code clarity and creates an unnecessary dependency on the view-model.</p>
<p>Let's instead add a <code>ux:Property</code> to the component which we can then data-bind at the point of instantiation:</p>
<pre><code class="language-xml"><Grid ux:Class="OnOffButtons" ColumnCount="2">
<bool ux:Property="Value" />
<Panel HitTestMode="LocalBounds">
<Text Value="On" />
<Clicked>
<Set this.Value="true" />
</Clicked>
</Panel>
<Panel>
<Text Value="Off" />
<Clicked>
<Set this.Value="false" />
</Clicked>
</Panel>
</Grid>
<JavaScript>
var Observable = require("FuseJS/Observable");
var status = Observable(false);
module.exports = {
status: status
};
</JavaScript>
<StackPanel Margin="10" Padding="10" Color="#eee" ItemSpacing="8">>
<Circle ux:Name="status" Width="40" Height="40" Color="Gray" />
<WhileTrue Value="{status}">
<Change status.Color="Green" />
</WhileTrue>
<WhileFalse Value="{status}">
<Change status.Color="Red" />
</WhileFalse>
</Circle>
<OnOffButtons Value="{status}" />
</StackPanel></code></pre>
<p>The "status" circle is at this point a good candidate for componentization as well, just to increase the readability and maintainability of our UX:</p>
<pre><code class="language-xml"><Grid ux:Class="OnOffButtons" ColumnCount="2">
<bool ux:Property="Value" />
<Panel HitTestMode="LocalBounds">
<Text Value="On" />
<Clicked>
<Set this.Value="true" />
</Clicked>
</Panel>
<Panel>
<Text Value="Off" />
<Clicked>
<Set this.Value="false" />
</Clicked>
</Panel>
</Grid>
<Circle ux:Class="StatusCircle" Width="40" Height="40" Color="Gray" />
<bool ux:Property="Status" />
<WhileTrue Value="{ReadProperty Status}">
<Change status.Color="Green" />
</WhileTrue>
<WhileFalse Value="{ReadProperty Status}">
<Change status.Color="Red" />
</WhileFalse>
</Circle>
<JavaScript>
var Observable = require("FuseJS/Observable");
var status = Observable(false);
module.exports = {
status: status
};
</JavaScript>
<StackPanel Margin="10" Padding="10" Color="#eee" ItemSpacing="8">>
<StatusCircle Status="{status}" />
<OnOffButtons Value="{status}" />
</StackPanel></code></pre>
<p>Now we have two independent components, with clearly defined interfaces.</p>
<h2 id="referencing-files-through-properties">Referencing files through properties</h2>
<p>There are cases where we would like to pass references to files to our components. Examples include embedding images or videos. We can do this by creating properties of the type <code>FileSource</code> and then property-bind the <code>File</code> property of the <code>Image</code> or <code>Video</code> object to it. Then we can reference local files by their path when we instantiate our class:</p>
<pre><code class="language-xml"><App>
<Panel ux:Class="TestComponent">
<FileSource ux:Property="ImageFile" />
<FileSource ux:Property="VideoFile" />
<Grid Rows="1*,1*">
<Image File="{ReadProperty ImageFile}" Margin="10" />
<Video File="{ReadProperty VideoFile}" AutoPlay="true" IsLooping="true" />
</Grid>
</Panel>
<TestComponent ImageFile="test.png" VideoFile="testvideo.mp4" />
</App></code></pre>
<h2 id="container">Container</h2>
<p>The <code>Container</code> class can be used as a base class when creating components that should position its children deeper into its own subtree. Here is a quick example:</p>
<pre><code class="language-xml"><Container ux:Class="MyContainer" Subtree="innerPanel">
<Rectangle ux:Binding="Children" CornerRadius="10" Margin="10">
<Stroke Color="Red" Width="2" />
<Panel Margin="10" ux:Name="innerPanel" />