Skip to content

Commit f3cf64d

Browse files
committed
Add load events
1 parent 8f996d1 commit f3cf64d

File tree

3 files changed

+48
-6
lines changed

3 files changed

+48
-6
lines changed

src/Flame/Html/Attribute.purs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -262,4 +262,4 @@ import Flame.Html.Attribute.Internal
262262
, yChannelSelector
263263
, innerHtml
264264
) as Exported
265-
import Flame.Html.Event (EventName, ToEvent, ToRawEvent, ToMaybeEvent, ToSpecialEvent, createEvent, createEventMessage, createRawEvent, onBlur, onBlur', onCheck, onClick, onClick', onChange, onChange', onContextmenu, onContextmenu', onDblclick, onDblclick', onDrag, onDrag', onDragend, onDragend', onDragenter, onDragenter', onDragleave, onDragleave', onDragover, onDragover', onDragstart, onDragstart', onDrop, onDrop', onError, onError', onFocus, onFocus', onFocusin, onFocusin', onFocusout, onFocusout', onInput, onInput', onKeydown, onKeydown', onKeypress, onKeypress', onKeyup, onKeyup', onMousedown, onMousedown', onMouseenter, onMouseenter', onMouseleave, onMouseleave', onMousemove, onMousemove', onMouseout, onMouseout', onMouseover, onMouseover', onMouseup, onMouseup', onReset, onReset', onScroll, onScroll', onSelect, onSelect', onSubmit, onSubmit', onWheel, onWheel') as Exported
265+
import Flame.Html.Event (EventName, ToEvent, ToRawEvent, ToMaybeEvent, ToSpecialEvent, createEvent, createEventMessage, createRawEvent, onBlur, onBlur', onCheck, onClick, onClick', onChange, onChange', onContextmenu, onContextmenu', onDblclick, onDblclick', onDrag, onDrag', onDragend, onDragend', onDragenter, onDragenter', onDragleave, onDragleave', onDragover, onDragover', onDragstart, onDragstart', onDrop, onDrop', onError, onError', onFocus, onFocus', onFocusin, onFocusin', onFocusout, onFocusout', onInput, onInput', onKeydown, onKeydown', onKeypress, onKeypress', onKeyup, onKeyup', onMousedown, onMousedown', onMouseenter, onMouseenter', onMouseleave, onMouseleave', onMousemove, onMousemove', onMouseout, onMouseout', onMouseover, onMouseover', onMouseup, onMouseup', onReset, onReset', onScroll, onScroll', onSelect, onSelect', onSubmit, onSubmit', onLoad, onLoad', onUnload, onUnload', onWheel, onWheel') as Exported

src/Flame/Html/Attribute/Event.purs

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
-- | Definition of HTML events that can be fired from views
2-
module Flame.Html.Event (EventName, ToEvent, ToRawEvent, ToMaybeEvent, ToSpecialEvent, createEvent, createEventMessage, createRawEvent, onBlur, onBlur', onCheck, onClick, onClick', onChange, onChange', onContextmenu, onContextmenu', onDblclick, onDblclick', onDrag, onDrag', onDragend, onDragend', onDragenter, onDragenter', onDragleave, onDragleave', onDragover, onDragover', onDragstart, onDragstart', onDrop, onDrop', onError, onError', onFocus, onFocus', onFocusin, onFocusin', onFocusout, onFocusout', onInput, onInput', onKeydown, onKeydown', onKeypress, onKeypress', onKeyup, onKeyup', onMousedown, onMousedown', onMouseenter, onMouseenter', onMouseleave, onMouseleave', onMousemove, onMousemove', onMouseout, onMouseout', onMouseover, onMouseover', onMouseup, onMouseup', onReset, onReset', onScroll, onScroll', onSelect, onSelect', onSubmit, onSubmit', onWheel, onWheel') where
2+
module Flame.Html.Event (EventName, ToEvent, ToRawEvent, ToMaybeEvent, ToSpecialEvent, createEvent, createEventMessage, createRawEvent, onBlur, onBlur', onCheck, onClick, onClick', onChange, onChange', onContextmenu, onContextmenu', onDblclick, onDblclick', onDrag, onDrag', onDragend, onDragend', onDragenter, onDragenter', onDragleave, onDragleave', onDragover, onDragover', onDragstart, onDragstart', onDrop, onDrop', onError, onError', onFocus, onFocus', onFocusin, onFocusin', onFocusout, onFocusout', onInput, onInput', onKeydown, onKeydown', onKeypress, onKeypress', onKeyup, onKeyup', onMousedown, onMousedown', onMouseenter, onMouseenter', onMouseleave, onMouseleave', onMousemove, onMousemove', onMouseout, onMouseout', onLoad, onLoad', onUnload, onUnload', onMouseover, onMouseover', onMouseup, onMouseup', onReset, onReset', onScroll, onScroll', onSelect, onSelect', onSubmit, onSubmit', onWheel, onWheel') where
33

44
import Prelude
55

@@ -69,6 +69,18 @@ onClick = createEvent "click"
6969
onClick' message. ToRawEvent message
7070
onClick' = createEventMessage "click"
7171

72+
onLoad message. ToEvent message
73+
onLoad = createEvent "load"
74+
75+
onLoad' message. ToRawEvent message
76+
onLoad' = createEventMessage "load"
77+
78+
onUnload message. ToEvent message
79+
onUnload = createEvent "unload"
80+
81+
onUnload' message. ToRawEvent message
82+
onUnload' = createEventMessage "unload"
83+
7284
onChange message. ToEvent message
7385
onChange = createEvent "change"
7486

src/Flame/Renderer/Internal/Dom.js

Lines changed: 34 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -365,7 +365,7 @@ F.prototype.runHandlers = function (handlers, messageMapper, event) {
365365
};
366366

367367
F.prototype.resume = function (updatedHtml) {
368-
this.cachedHtml = this.updateAllNodes(this.root, this.cachedHtml, updatedHtml);;
368+
this.cachedHtml = this.updateAllNodes(this.root, this.cachedHtml, updatedHtml);
369369
};
370370

371371
/** Patches over the parent element*/
@@ -375,9 +375,14 @@ F.prototype.updateAllNodes = function (parent, currentHtml, updatedHtml) {
375375
updatedHtml = shallowCopy(updatedHtml);
376376
//recreate node if it has changed tag or node type
377377
if (currentHtml.tag !== updatedHtml.tag || currentHtml.nodeType !== updatedHtml.nodeType) {
378-
//moving the node instead of using clearNode allows us to reuse nodes
379-
this.createAllNodes(parent, updatedHtml, currentHtml.node);
380-
parent.removeChild(currentHtml.node);
378+
if (currentHtml.nodeType === fragmentNode) {
379+
this.createAllNodes(parent, updatedHtml, firstFragmentChildNode(currentHtml.children));
380+
removeFragmentChildren(parent, currentHtml.children);
381+
} else {
382+
//moving the node instead of using clearNode allows us to reuse nodes
383+
this.createAllNodes(parent, updatedHtml, currentHtml.node);
384+
parent.removeChild(currentHtml.node);
385+
}
381386
}
382387
else {
383388
updatedHtml.node = currentHtml.node;
@@ -434,6 +439,31 @@ F.prototype.updateAllNodes = function (parent, currentHtml, updatedHtml) {
434439
return updatedHtml;
435440
};
436441

442+
/** Fragments are not child of any nodes, so we must find the first actual node */
443+
function firstFragmentChildNode(children) {
444+
let childrenLength = children.length;
445+
446+
for (let i = 0; i < childrenLength; ++i) {
447+
if (children[i].nodeType === fragmentNode)
448+
return firstFragmentChildNode(children[i].children);
449+
450+
return children[i].node;
451+
}
452+
453+
return undefined;
454+
}
455+
456+
/** fragments are not child of any nodes, so we must recursively remove the actual child nodes */
457+
function removeFragmentChildren(parent, children) {
458+
let childrenLength = children.length;
459+
460+
for (let i = 0; i < childrenLength; ++i)
461+
if (children[i].nodeType === fragmentNode)
462+
removeFragmentChildren(children[i].children)
463+
else
464+
parent.removeChild(children[i].node);
465+
}
466+
437467
function clearNode(node) {
438468
node.textContent = '';
439469
}

0 commit comments

Comments
 (0)