Skip to content

Add support for lydell’s fork of elm/virtual-dom #40

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 2 commits into
base: lamdera-next
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion compiler/src/Generate/Html.hs
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ sandwich root moduleName javascript =

<body>

<pre id="elm"></pre>
<pre data-elm id="elm"></pre>

<script>
try {
Expand Down
33 changes: 30 additions & 3 deletions extra/Lamdera/Injection.hs
Original file line number Diff line number Diff line change
Expand Up @@ -484,6 +484,7 @@ injections outputType mode =

$lamderaContainersExtensions_

var _VirtualDom_equalEvents; // For lydell’s vdom.
function _Platform_initialize(flagDecoder, args, init, update, subscriptions, stepperBuilder)
{
var result = A2(_Json_run, flagDecoder, _Json_wrap(args ? args['flags'] : undefined));
Expand Down Expand Up @@ -542,10 +543,20 @@ injections outputType mode =
};

_VirtualDom_applyPatches = function(rootDomNode, oldVirtualNode, patches, eventNode) {
if (patches.length !== 0) {
_VirtualDom_addDomNodes(rootDomNode, oldVirtualNode, patches, eventNode);
if (typeof _VirtualDom_wrap === 'function') { // For lydell’s vdom.
_VirtualDom_renderCount++;
var instance = rootDomNode.elmInstance || _VirtualDom_instanceCount++;
_VirtualDom_instance = '_' + instance;
var diffReturn = _VirtualDom_diffHelp(oldVirtualNode, patches, eventNode);
_VirtualDom_lastDomNode = diffReturn.w;
_VirtualDom_lastDomNode.elmInstance = instance;
_VirtualDom_instance = '';
} else {
if (patches.length !== 0) {
_VirtualDom_addDomNodes(rootDomNode, oldVirtualNode, patches, eventNode);
}
_VirtualDom_lastDomNode = _VirtualDom_applyPatchesHelp(rootDomNode, patches);
}
_VirtualDom_lastDomNode = _VirtualDom_applyPatchesHelp(rootDomNode, patches);
// Restore the event listeners on the <a> elements:
var aElements = _VirtualDom_lastDomNode.getElementsByTagName('a');
for (var i = 0; i < aElements.length; i++) {
Expand Down Expand Up @@ -703,6 +714,10 @@ injections outputType mode =
function _VirtualDom_diff(x, y)
{
_VirtualDom_lastVNode = y;
if (typeof _VirtualDom_wrap === 'function') // For lydell’s vdom.
{
return y;
}
var patches = [];
_VirtualDom_diffHelp(x, y, patches, 0);
return patches;
Expand All @@ -712,6 +727,18 @@ injections outputType mode =
var _VirtualDom_lastDomNode = null;
function _VirtualDom_applyPatches(rootDomNode, oldVirtualNode, patches, eventNode)
{
if (typeof _VirtualDom_wrap === 'function') // For lydell’s vdom.
{
_VirtualDom_renderCount++;
var instance = rootDomNode.elmInstance || _VirtualDom_instanceCount++;
_VirtualDom_instance = '_' + instance;
var diffReturn = _VirtualDom_diffHelp(oldVirtualNode, patches, eventNode);
_VirtualDom_lastDomNode = diffReturn.w;
_VirtualDom_lastDomNode.elmInstance = instance;
_VirtualDom_instance = '';
return _VirtualDom_lastDomNode;
}

if (patches.length === 0)
{
return (_VirtualDom_lastDomNode = rootDomNode);
Expand Down