@@ -9,19 +9,16 @@ Sugar smooths over browser differences and gives us useful functions for manipul
99When using Sugar, we don't use native DOM elements, we wrap them in the SugarElement data type.
1010This encourages us to only use Sugar functions to manipulate these elements, rather than the native DOM directly.
1111
12- NOTE: Like Option=>Optional, Sugar is in the process of renaming. This tutorial is using the old libraries, but we'll
13- rename imports to use the new names.
14-
1512Wrapping
1613
1714The first thing we need to know is how to wrap and unwrap a sugar element.
1815 */
1916
2017
21- const e1 : Element = document . createElement ( 'span' ) ;
18+ const e1 : HTMLSpanElement = document . createElement ( 'span' ) ;
2219
2320// wrapping
24- const se1 : SugarElement < Element > = SugarElement . fromDom ( e1 ) ;
21+ const se1 : SugarElement < HTMLSpanElement > = SugarElement . fromDom ( e1 ) ;
2522
2623// unwrapping
2724const e2 : Element = se1 . dom ;
@@ -32,11 +29,11 @@ Pretty simple so far.
3229Now, above, we used `document.createElement`. We want to use Sugar functions everywhere, so we should do this instead:
3330 */
3431
35- const se2 : SugarElement < Element > = SugarElement . fromTag ( 'span' ) ;
32+ const se2 : SugarElement < HTMLSpanElement > = SugarElement . fromTag ( 'span' ) ;
3633
3734// or
3835
39- const se3 : SugarElement < Element > = SugarElement . fromTag ( 'span' , document ) ;
36+ const se3 : SugarElement < HTMLSpanElement > = SugarElement . fromTag ( 'span' , document ) ;
4037
4138/*
4239It's useful to be able to pass in a document parameter to this function, since we're often dealing with iframes as well
@@ -50,8 +47,8 @@ TODO: Use SugarElement's fromHtml and fromText functions to create a few element
5047We often have to traverse from an element to its relatives. The Traverse module has useful functions for this.
5148 */
5249( ) => {
53- const parent : SugarElement < Element > = SugarElement . fromTag ( 'div' ) ;
54- const kid : SugarElement < Element > = SugarElement . fromTag ( 'span' ) ;
50+ const parent : SugarElement < HTMLDivElement > = SugarElement . fromTag ( 'div' ) ;
51+ const kid : SugarElement < HTMLSpanElement > = SugarElement . fromTag ( 'span' ) ;
5552 Insert . append ( parent , kid ) ;
5653
5754 const parent2 = Traverse . parent ( kid ) ;
@@ -63,9 +60,9 @@ We often have to traverse from an element to its relatives. The Traverse module
6360
6461
6562( ) => {
66- const parent : SugarElement < Element > = SugarElement . fromTag ( 'div' ) ;
67- const kid1 : SugarElement < Element > = SugarElement . fromTag ( 'span' ) ;
68- const kid2 : SugarElement < Element > = SugarElement . fromTag ( 'div' ) ;
63+ const parent : SugarElement < HTMLDivElement > = SugarElement . fromTag ( 'div' ) ;
64+ const kid1 : SugarElement < HTMLSpanElement > = SugarElement . fromTag ( 'span' ) ;
65+ const kid2 : SugarElement < HTMLDivElement > = SugarElement . fromTag ( 'div' ) ;
6966 Insert . append ( parent , kid1 ) ;
7067 Insert . append ( parent , kid2 ) ;
7168
0 commit comments