-
Notifications
You must be signed in to change notification settings - Fork 77
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
11 changed files
with
201 additions
and
19 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,70 @@ | ||
// var request = require('request') | ||
var nanoajax = require('nanoajax') | ||
// var yo = require('yo-yo') | ||
|
||
// script injected in development mode | ||
function updateStream (target, callback) { | ||
var es = new window.EventSource(target) | ||
|
||
es.addEventListener('message', function (e) { | ||
nanoajax.ajax({url: target}, function (code, text) { | ||
callback(null, text) | ||
}) | ||
}) | ||
} | ||
|
||
function toArray (list) { | ||
return Array.prototype.slice.call(list) | ||
} | ||
|
||
function main () { | ||
var scripts = toArray(document.querySelectorAll('script[data-bankai-hmr]')) | ||
var styles = toArray(document.querySelectorAll('link[data-bankai-hmr]')) | ||
|
||
scripts.forEach(function (script) { | ||
updateStream(script.src, function (error, data) { | ||
if (error) { | ||
console.error(error) | ||
} | ||
var el = document.createElement('script') | ||
var prev = document.querySelector('[data-bankai-hmr-copy="' + script.src + '"]') | ||
el.text = data | ||
el.setAttribute('data-bankai-hmr-copy', script.src) | ||
|
||
if (prev) { | ||
prev.parentNode.replaceChild(el, prev) | ||
} else { | ||
script.parentNode.insertBefore(el, script.nextSibling) | ||
} | ||
|
||
var id = script.dataset.bankaiHmr | ||
var application = require(id) | ||
var app = application(window.__BANKAI_GLOBAL_STATE_HOOK__, { | ||
onStateChange: function (data, state) { window.__BANKAI_GLOBAL_STATE_HOOK__ = state } | ||
}) | ||
var tree = app.start() | ||
document.body.replaceChild(tree, document.body.firstChild) | ||
// yo.update(old, tree) | ||
}) | ||
}) | ||
|
||
styles.forEach(function (style) { | ||
updateStream(style.href, function (error, data) { | ||
if (error) { | ||
console.error(error) | ||
} | ||
var el = document.createElement('style') | ||
var prev = document.querySelector('[data-bankai-hmr-copy="' + style.href + '"]') | ||
el.setAttribute('data-bankai-hmr-copy', style.href) | ||
el.appendChild(document.createTextNode(data)) | ||
|
||
if (prev) { | ||
prev.parentNode.replaceChild(el, prev) | ||
} else { | ||
style.parentNode.insertBefore(el, style.nextSibling) | ||
} | ||
}) | ||
}) | ||
} | ||
|
||
main() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,3 @@ | ||
h1 { | ||
color: blue; | ||
color: red; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters