Skip to content

Commit 980e07e

Browse files
committed
Closes #53
1 parent 5239e99 commit 980e07e

File tree

11 files changed

+65
-74
lines changed

11 files changed

+65
-74
lines changed

package-lock.json

Lines changed: 16 additions & 10 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/Flame/Html/Attribute/Internal.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,13 +6,13 @@ let styleData = 1,
66
attributeData = 4,
77
keyData = 7;
88

9-
export function createProperty_(name) {
9+
export function createProperty(name) {
1010
return function (value) {
1111
return [propertyData, name, value];
1212
};
1313
}
1414

15-
export function createAttribute_(name) {
15+
export function createAttribute(name) {
1616
return function (value) {
1717
return [attributeData, name, value];
1818
};

src/Flame/Html/Attribute/Internal.purs

Lines changed: 9 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -18,8 +18,6 @@ import Partial.Unsafe as PU
1818
import Prelude (const, flip, map, not, otherwise, show, ($), (<<<), (<>), (==))
1919
import Type.Row.Homogeneous (class Homogeneous)
2020

21-
type Name = String
22-
type Value = String
2321

2422
type ToStringAttribute = ToNodeData String
2523

@@ -33,43 +31,37 @@ type ToNumberAttribute = ToNodeData Number
3331
class ToClassList a where
3432
to :: a -> Array String
3533

36-
instance stringClassList :: ToClassList String where
34+
instance ToClassList String where
3735
to = DA.filter (not <<< DS.null) <<< DS.split (Pattern " ")
3836

39-
instance recordClassList :: Homogeneous r Boolean => ToClassList { | r } where
37+
instance Homogeneous r Boolean => ToClassList { | r } where
4038
to = FO.keys <<< FO.filterWithKey (flip const) <<< FO.fromHomogeneous
4139

4240
-- | Enables either tuples, arrays or records be used as an argument to `style`
4341
class ToStyleList a where
4442
toStyleList :: a -> Object String
4543

46-
instance tupleStyleList :: ToStyleList (Tuple String String) where
44+
instance ToStyleList (Tuple String String) where
4745
toStyleList (Tuple a b) = FO.singleton a b
4846
else
49-
instance recordStyleList :: Homogeneous r String => ToStyleList { | r } where
47+
instance Homogeneous r String => ToStyleList { | r } where
5048
toStyleList = FO.fromFoldable <<< map go <<< toArray
5149
where go (Tuple name' value') = Tuple (caseify name') value'
5250
toArray :: _ -> Array (Tuple String String)
5351
toArray = FO.toUnfoldable <<< FO.fromHomogeneous
5452
else
55-
instance foldableStyleList :: DF.Foldable f => ToStyleList (f (Tuple String String)) where
53+
instance DF.Foldable f => ToStyleList (f (Tuple String String)) where
5654
toStyleList = FO.fromFoldable
5755

5856
--these functions cheat by only creating the necessary key on NodeData
59-
foreign import createProperty_ :: forall message. Name -> Value -> (NodeData message)
60-
foreign import createAttribute_ :: forall message. Name -> Value -> (NodeData message)
57+
-- | Sets a DOM property
58+
foreign import createProperty :: forall message. String -> String -> NodeData message
59+
-- | Creates a HTML attribute
60+
foreign import createAttribute :: forall message. String -> String -> NodeData message
6161
foreign import createClass :: forall message. Array String -> NodeData message
6262
foreign import createStyle :: forall message. Object String -> NodeData message
6363
foreign import createKey :: forall message. String -> NodeData message
6464

65-
-- | Sets a DOM property
66-
createProperty :: forall message. String -> String -> NodeData message
67-
createProperty name value = createProperty_ name value
68-
69-
-- | Creates a HTML attribute
70-
createAttribute :: forall message. String -> String -> NodeData message
71-
createAttribute name value = createAttribute_ name value
72-
7365
booleanToFalsyString :: Boolean -> String
7466
booleanToFalsyString =
7567
case _ of

src/Flame/Html/Element.js

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
let textNode = 1,
22
elementNode = 2,
33
svgNode = 3,
4-
fragmentNode = 4,
54
lazyNode = 5,
65
managedNode = 6;
76
let styleData = 1,
@@ -74,13 +73,6 @@ export function createEmptyElement(tag) {
7473
};
7574
}
7675

77-
export function createFragmentNode(children) {
78-
return {
79-
nodeType: fragmentNode,
80-
node: undefined,
81-
children: children
82-
};
83-
}
8476

8577
export function text(value) {
8678
return {

src/Flame/Html/Element.purs

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ import Data.Maybe as DM
99
import Effect (Effect)
1010
import Flame.Html.Attribute.Internal as FHAI
1111
import Flame.Types (Html, NodeData, Tag, Key)
12+
import Flame.Internal.Fragment as FIF
1213
import Web.DOM (Node)
1314

1415
-- | `ToNode` simplifies element creation by automating common tag operations
@@ -19,19 +20,19 @@ class ToNode :: forall k. Type -> k -> (k -> Type) -> Constraint
1920
class ToNode a b c | a -> b where
2021
toNode :: a -> Array (c b)
2122

22-
instance stringToHtml :: ToNode String b Html where
23+
instance ToNode String b Html where
2324
toNode = DA.singleton <<< text
2425

25-
instance arrayToNodeData :: (ToNode a b c) => ToNode (Array a) b c where
26+
instance (ToNode a b c) => ToNode (Array a) b c where
2627
toNode = DA.concatMap toNode
2728

28-
instance htmlToHtml :: ToNode (Html a) a Html where
29+
instance ToNode (Html a) a Html where
2930
toNode = DA.singleton
3031

31-
instance stringToNodeData :: ToNode String b NodeData where
32+
instance ToNode String b NodeData where
3233
toNode = DA.singleton <<< FHAI.id
3334

34-
instance nodeDataToNodedata :: ToNode (NodeData a) a NodeData where
35+
instance ToNode (NodeData a) a NodeData where
3536
toNode = DA.singleton
3637

3738
type ToHtml a b h = ToNode a h NodeData => ToNode b h Html => a -> b -> Html h
@@ -51,7 +52,6 @@ type NodeRenderer arg = {
5152
foreign import createElementNode :: forall message. Tag -> Array (NodeData message) -> Array (Html message) -> Html message
5253
foreign import createDatalessElementNode :: forall message. Tag -> Array (Html message) -> Html message
5354
foreign import createSingleElementNode :: forall message. Tag -> Array (NodeData message) -> Html message
54-
foreign import createFragmentNode :: forall message. Array (Html message) -> Html message
5555

5656
--separate functions as svg are special babies
5757
foreign import createSvgNode :: forall message. Array (NodeData message) -> Array (Html message) -> Html message
@@ -85,7 +85,7 @@ createElement' tag nodeData = createSingleElementNode tag $ toNode nodeData
8585
-- |
8686
-- | Fragments act as wrappers: only children nodes are rendered
8787
fragment :: forall b h. ToHtml_ b h
88-
fragment children = createFragmentNode $ toNode children
88+
fragment children = FIF.createFragmentNode $ toNode children
8989

9090
-- | Creates a lazy node
9191
-- |

src/Flame/Internal/Equality.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
export function compareReference_(a) {
1+
export function compareReference(a) {
22
return function (b) {
33
return a === b;
4-
};
4+
}
55
}

src/Flame/Internal/Equality.purs

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,7 @@ module Flame.Internal.Equality where
22

33
import Prelude (not, ($))
44

5-
foreign import compareReference_ :: forall a. a -> a -> Boolean
6-
7-
compareReference :: forall a. a -> a -> Boolean
8-
compareReference a a2 = compareReference_ a a2
5+
foreign import compareReference :: forall a. a -> a -> Boolean
96

107
modelHasChanged :: forall model. model -> model -> Boolean
118
modelHasChanged old new = not $ compareReference old new

src/Flame/Internal/Fragment.js

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
let fragmentNode = 4;
2+
3+
export function createFragmentNode(children) {
4+
return {
5+
nodeType: fragmentNode,
6+
node: undefined,
7+
children: children
8+
};
9+
}

src/Flame/Internal/Fragment.purs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
module Flame.Internal.Fragment where
2+
3+
foreign import createFragmentNode :: forall html message. Array (html message) -> html message

src/Flame/Renderer/Internal/Dom.js

Lines changed: 7 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ function F(eventWrapper, root, updater, html, isDry) {
3737
/** The current virtual nodes to be diff'd when the view updates */
3838
this.cachedHtml = html.node === undefined ? html : shallowCopy(html); //if node is already defined, then this object has been reused in views
3939

40-
//a "dry" application means that it was server side rendered
40+
//"dry" application means that it was server side rendered
4141
if (isDry)
4242
this.hydrate(this.root, this.cachedHtml);
4343
else
@@ -192,24 +192,9 @@ F.prototype.createChildrenNodes = function (parent, children) {
192192
let childrenLength = children.length;
193193

194194
for (let i = 0; i < childrenLength; ++i) {
195-
let c = children[i] = (children[i].node === undefined ? children[i] : shallowCopy(children[i])),
196-
node = this.createNode(c);
195+
let html = children[i] = (children[i].node === undefined ? children[i] : shallowCopy(children[i]));
197196

198-
if (c.text !== undefined)
199-
node.textContent = c.text;
200-
else {
201-
if (c.children !== undefined)
202-
this.createChildrenNodes(node, c.children);
203-
else if (c.rendered !== undefined) {
204-
if (c.messageMapper !== undefined)
205-
lazyMessageMap(c.messageMapper, c.rendered);
206-
207-
if (c.rendered.children !== undefined)
208-
this.createChildrenNodes(node, c.rendered.children);
209-
}
210-
}
211-
212-
parent.appendChild(node);
197+
this.checkCreateAllNodes(parent, html, null);
213198
}
214199
};
215200

@@ -303,7 +288,7 @@ function createAttributes(node, attributes) {
303288
node.setAttribute(key, attributes[key]);
304289
}
305290

306-
/** Creates synthethic events
291+
/** Creates synthetic events
307292
*
308293
* If the event bubbles, a single listener for its type is added to the root, and fired at the nearest node from the target that contains a handler. Otherwise the event is added to the node */
309294
F.prototype.createAllEvents = function (node, html) {
@@ -328,9 +313,9 @@ F.prototype.createEvent = function (node, name, html) {
328313
if (html.messageMapper !== undefined)
329314
node[eventKey + eventPostfix] = html.messageMapper;
330315

331-
let synthethic = this.applicationEvents.get(name);
316+
let synthetic = this.applicationEvents.get(name);
332317

333-
if (synthethic === undefined) {
318+
if (synthetic === undefined) {
334319
let runEvent = this.runEvent.bind(this);
335320

336321
this.root.addEventListener(name, runEvent, false);
@@ -340,7 +325,7 @@ F.prototype.createEvent = function (node, name, html) {
340325
});
341326
}
342327
else
343-
synthethic.count++;
328+
synthetic.count++;
344329
}
345330
};
346331

0 commit comments

Comments
 (0)